I have a react component structure like this:
In my table component, I have an option to trigger a modal that prompts user to give some input, which will then send a put request to the backend. In code it looks something like this:
const ParentContainer = (): JSX.Element => {
const dataToPassDown = useSelector((state:IRootState) => selectData(state));
return (
<ParentComponent data={dataToPassDown}/>
)
}
const ParentComponent = (props): JSX.Element => {
const {data} = props;
return (
<MyHeader data = {data}/>
<MyTable data = {data.tableData} />
)
}
const MyTable = (props): JSX.Element => {
const {data} = props;
const [inputFromModal, setInputFromModal] = useState("");
const dispatch = useDispatch();
useEffect(() => {
dispatch(putRequest(inputFromModal);
}, [inputFromModal]);
return (
<Modal visible={false} updateInputValue={setInputFromModal}/>
<Table ... />
)
}
I want to refresh (only) the table component once the modal closes, but in this current setup, useEffect doesn't reload the table component when its state (inputFromModal) changes. Was I wrong in thinking that useEffect would reload the component when the state changed?
