Thx. I thought assigning a function to a const would not call the function until the const was called. I was wrong. For reference to others I solved it like this.
function Extension() {
const [shop, setShop] = useState('');
const deliveryGroups = useDeliveryGroups();
const { selectedDeliveryOption } = useDeliveryGroup(deliveryGroups[0]);
const applyShippingAddressChange = useApplyShippingAddressChange();
const delCode = selectedDeliveryOption?.code ? selectedDeliveryOption.code : '';
useEffect(() => {
if (delCode.includes('pakkeshopper')){
setShop(delCode)
}
applyShippingAddressChange({
type: 'updateShippingAddress',
address: {
city: shop.city
}
})
}, [delCode]);
}