I'm working with functional component and seem to be bit stuck with props not updating as expected. I have a function to submit my changes and after submit I notice the props are not updated though I'm calling get method again. Any advice or guidance will be much aprreciated.
Here's an example of my code snippet:
useEffect(() => { props.getData().then(setData({ ...props.dataDetails })) }, [props.dataDetails.name]) ;
const handleSubmit = () => {
props.updateData(data).then(
props.getData().then(() => {
console.log(props.dataDetails);
setData({ ...props.dataDetails })
})
};
In the above code after submitting the data though I'm calling getData, in the console log I noticed the value of props.dataDetails is still the old props value. How can I ensure that the props value is updated?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/rxjRPaZ
Comments
Post a Comment