How can i get the provinceCode updated?

Solved

How can i get the provinceCode updated?

JtorresLC
Shopify Partner
5 1 1

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
5 1 1

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
1829 271 413

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
5 1 1

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
5 1 1

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.