For discussing the development and usage of Checkout UI extensions, post-purchase extensions, web pixels, Customer Accounts UI extensions, and POS UI extensions
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.
Solved! Go to the solution
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.
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
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.
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.