Search code examples
javascriptreactjsreloaddom-manipulation

DOM Maniulation and page reload in ReactJS


I need to reload the page on sign out (from header component) and then reloading the page to set it to initial view.

If I don't reload the page, though it logs out, it keeps on showing the error (shown for the previous logged in user).

How are DOM manipulation and page reload related in JS or ReactJS?

componentWillReceiveProps(nextProps) {
 /* on log out */
  if(!nextProps.user.isEmpty() && !isEqual(this.props.user, nextProps.user)){
    this.props.getData();
    window.location.reload();
  } 
}

Solution

  • What you should do is to reset all state in the application when the user has logged out. For example, if you are using Redux, then when the user logs out, you need to fire some action that will reset all state throughout the entire application.

    This should also ideally force the view to go back to the Login or initial page of the application.