Tell us what’s happening:
Describe your issue in detail here.
Why am I getting null when trying to send data back up from the child to the parent component here? https://codesandbox.io/s/autumn-http-wync7?file=/src/App.js
Your code so far
const JSX = <div></div>;
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36
Challenge: Create a Simple JSX Element
Link to the challenge:
Hi, @ozzyMosbourne , welcome to the forum!
In your code, I see this.
const changePlaceHandler = (city) => {
setLocation(city);
console.log(location);
};
setLocation is an asynchronous function, so location is not yet updated when you try to console.log it.
Try logging city instead.
1 Like
Thank you, but how can I pass city as props to the component below Search, if setting city using state won’t work?
Using state does work. It’s just not updated yet when you try to console.log in changePlaceHandler. Try rendering out `location’ right below your child component.
1 Like
you’re the best, sir. thank youuuuu
1 Like
system
Closed
May 3, 2022, 2:30am
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.