I encountered such a problem that when we have a child component whose state depends on the props of the parent, this does not work quite correctly, I would like to know if it is possible to solve this problem using useLayaoutEffect or what is the best way?
Example
Parent
const Parent = () => {
const [filled, setFilled] = useState(false)
useEffect(()=>{
..some logic
setFilled(true)
},[])
return <Input isFilled={isFilled}/>
}
Child
const Input = (props) => {
const [filled, setFilled] = useState(props.isFilled || false)
// when isFilled changes child components doens't notified about this changes,
// so can we solve this with useLayoutEffect?
useLayoutEffect(()=>{
setFilled(props.isFilled || false)
},[props.isFilled])
}
This example may be very simple and silly, but I think the essence of the problem should be clear.