score:3
Accepted answer
You need to tell useEffect which variables to track, Change to
useEffect(() => {
if (props.mode === 'view') {
alert('Initializing in View Mode')
} else {
alert('NOT initializing in View Mode');
}
}, [props.mode]);
(Note added by OP per responder's later comment: When React sees the same component on a new route, it will act as if merely the props have changed, but will not create a brand-new component that would have gone through useEffect(.., [])
(initialization.)
Source: stackoverflow.com
Related Query
- React Router with different paths on same component: does not re-initialize component (useEffect [] not called)
- React Router switch does not mount same component for different routes
- React router does not reload component if same element is used for two paths
- React Router Link to same component with different URL not re-rendering
- Using the same component for different Routes with React Router
- React Router trigger re-load / re-mount component on redirecting to same page with different slug
- React Router "Link to" does not load new data when called from inside the same component
- Render Same Component With Multiple Paths React Router Dom
- Same component with different parameters is not updating in react
- React Router Switch statement with routes grouped as component inside does not go to Not Found route
- conditional rendering of the same component with different props does not unmount the component in ReactJS
- react router changing to current page with different params does not work
- React router 4 - Why is my component only rendered on manually setting the url but not on clicking a Link with same url?
- For different route, same react component does not get mounted
- React Router v4 - Redirect to same route with different query params
- Basename does not seem to be taken into account with matchPath in react router
- Cannot render same route with different parameters react router v4
- Property does not exist on React component when defined with recompose
- React router dom redirect problem. Changes url, does not render component
- React Router does not render Component
- React Router this.context.router.push does not remount the component
- React Router useHistory. History.push changes url but does not load component
- Same route path with different component in React
- React Router does not update component if url parameter changes
- React Routing to Same Component with Different URL
- React router dom passing data from parent component to child router component does not pass the props.match
- Property does not exist on state - Using React Router Hooks with TypeScript
- route.component does not have any construct or call signatures - React Router with TypeScript
- React JSX with component in variable does not sync props
- Problem rendering Component in a different page with React Router
More Query from same tag
- In Redux, replace dispatch in action creator
- How to handle Unhandled Rejection from third party?
- TypeScript doesn't catch error with incorrect interface props when setting state - React
- ReactJS adding a data to a specific row from my custom table
- Using material-ui with redux?
- Overwriting a specific materialUI class
- Electron app freezes in production build when there are no errors and no memory leaks, what have I done wrong?
- Solana JSON RPC API getBalance method always returns 0
- How does the state updates of objects in React work accurately
- How to export variable from react component?
- TS2322: Type error while im using useContext with a function
- Jest: How to mock default export Component when same module also has named export?
- Use calc function in CSS in JS in React component
- TypeError: stripHtml is not a function
- How to solve 'this.props.items is undefined' in React.js on Firefox?
- React Native getInitialState() syntax error (unexpected token)
- How can I filter a set of data based on 4 conditions?
- Change the format of JSON object
- this.props.yyy is not a function
- How to use SetState or function with firebase
- How to show/hide ReactJS components
- how can i send text from a rich text editor into a sql database?
- How to map JSON data as a table in React
- Converting XML data to JSON on ReactJs
- Fetch Api cannot load webpack
- Reactjs Unexpected token Error Only On Windows, Not Linux
- Reactjs with fetch for auth and access token, not able to parse response
- React updating a components state from another component causes infinite loop
- React Prevent re-fetching on page changing
- EventManager for Reactjs throws "addHandler is not a function"