I'm using this (below Redirect from react-router-dom) to move from my Edit component to Profile component after updating some user info.
Example:-
<Redirect
to={{
pathname: `/user/${id}`,
state: { message: 'Profile updated!' }
}}
/>
As soon as my Profile component mounts i do this
toast.configure();
if (this.props.location.state !== undefined) {
toast.success(this.props.location.state.message, {
position: toast.POSITION.BOTTOM_LEFT
});
this.props.location.state = undefined;
} else {
toast.success('');
}
But the problem is, even if the this.props.location.state.message is undefined, as its showing in the React Dev tools, the toast still pops up every time i refresh the page with the message "Profile updated!"
i had to do this part
...this.props.location.state = undefined;
} else {
toast.success('');
}
to make it work somehow. Still no luck. Please help.