I got { ‘useState’ is not defined no-undef } error while compiling React. App was doing just fine until I moved a component into a separate file, here’s the code
I would be lying if I said that I never made the same mistake. Another common one is to import a named export as default or vice versa and you can’t figure out why it is undefined. These things happen.
By the way, can you help me with another thing there? I’m stuck again at my project, now I don’t know how to interact between my two components. I have one that has input in it and I wanted to make it so when the button is clicked, the input value is being passed to its sibling component, but I’ve just realized that I have no idea how to do that
Most basically, store that state in a component that is an ancestor to both child components. Passing the data down is easy enough. To allow the other child to change its ancestor’s state, pass a callback function down to the children.
But on the most basic level, first you need to know how to do #1. This is such a common point of confusion that I created a pen to demonstrate the concept.