Use this snippet when you have created a menu using BrowserRouter from 'react-router-dom' and you need to reset the state when you click on the current menu item (same url path as you are currently on).
Source code viewer
componentWillReceiveProps(nextProps) { if (nextProps.location.pathname === window.location.pathname) { this.setState({...this.initialState}) } }Programming Language: ECMAScript