I'm trying to update boolean usestate variable value in first component based on some method call completion in second component. But usestate boolean value doesnt seem to get update in first component.
Below is my sample code
function Component2(props){
cosnt{handle}=props
function handle(){
locate();
}
return(
call handle function above
)
export default Component2
}
function Component1(props){
const[show,SetShow]=useState(false)
function locate(){
setShow(!show)
}
return(
call compoent2
<Component2 handle={handle}>
)
export default Component1
can you please assist why simple setstate for boolean variable not working in component1 on calling from component2. it always remain false. On placing debugger it is confirmed method being called from component2 and call has reached completed in component1, still boolean value remain false.
In this modified version:
This way, when the function passed from Component1 to Component2 is called, it updates the state of Component1, and the component re-renders with the updated state.