Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How can i get the provinceCode updated?

Solved

How can i get the provinceCode updated?

JtorresLC
Shopify Partner
6 1 2

JtorresLC_0-1705350060322.png

 

I need to get the provinceCode in the checkout delivery form.

this code only gets the provinceCode the first time, how can I get the updated provinceCode when the customer changes it?, need to take the correct any time any customer decide to change it.

 

Accepted Solution (1)

JtorresLC
Shopify Partner
6 1 2

This is an accepted solution.

I found a solution, using:

let address = useShippingAddress();

then use address as the argument of useEffect, the effect refresh and give me the updated data.

View solution in original post

Replies 3 (3)

SBD_
Shopify Staff
1831 273 423

Hey @JtorresLC 

 

You should be able to tell useEffect that provinceCode is a dependency (via the second argument), which will cause the function to run each time the province code changes:

 

const [provinceCode] = useShippingAddress();
useEffect(() => {
  console.log(provinceCode);
}, [provinceCode]);

 

Scott | Developer Advocate @ Shopify 

JtorresLC
Shopify Partner
6 1 2

For sure that could be a solution, however im reading province variable wich is in a useState, so I figure this can't upload by itself.

so knowing that, I need a way to get a new provice code when the customer made a change, and from it use de setState toupdate as expected.

JtorresLC_0-1705411160942.png

 

JtorresLC
Shopify Partner
6 1 2

This is an accepted solution.

I found a solution, using:

let address = useShippingAddress();

then use address as the argument of useEffect, the effect refresh and give me the updated data.