score:2
componentdidmount
is only called once and is invoked immediately after a component is mounted. so it won't have any effect if your props change.
this should work. you can use the componentdidupdate
method. it will run after the updating has happened.
componentdidupdate(prevprops, prevstate) {
if (prevprops.selectedtype !== this.props.selectedtype) {
// do something
}
}
hope this helps!
score:2
componentdidmount
calls only once, and doesn't react on any props changing
componentdidmount() is invoked immediately after a component is mounted (inserted into the tree). initialization that requires dom nodes should go here. if you need to load data from a remote endpoint, this is a good place to instantiate the network request.
for reaction on some props changing you have to use componentdidupdate
componentdidupdate() is invoked immediately after updating occurs. this method is not called for the initial render.
notes:
componentwillreceiveprops
is deprecated. please don't use it.
read the react documentation. it's base thing for development of good website
Source: stackoverflow.com
Related Query
- React - Rendered item is not updating after initial render. When props change, should select different data
- Props not updating when redux state change in React Hooks
- Component not updating when I change the props that I pass to it in React
- React JS Not Completely Updating View When Render Is Called With New Props
- React child component not updating when props change
- React - Component not updating after props change
- React useState hooks initial value is null, after few seconds when got value then not updating where is use the value
- Props not updating when I change the store in react
- React with render props - component not updating on props change
- React Child Component Not Updating After Parent State Change
- React shouldComponentUpdate() is called even when props or state for that component did not change
- React Mobx - component not updating after store change
- React component not re-rendering after props change
- React Testing Library does not find elements using getAllByTestId after initial render
- React hook useLayoutEffect not updating ref parameter on initial render
- Functional Component in React is not updating on props change
- How to make my component re render after updating props from selector in react and redux-saga?
- React updating UI after a change in Props feeded to useReducer
- React Not Updating Render After SetState
- Tailwind CSS classes not updating after initial build of react app
- React not rerendering props when render function is provided
- Implement shouldComponentUpdate with React hooks - Render child only once, but make DOM changes when props change
- React -JS timer is not updating when i change the arrow function to simple function?
- react redux UI not updating after store change
- React functional component is not rendering when updating the Sate after pushing data to array
- React server side rendering is not updating after client side route change
- React child not re-rendered when parents props change
- react router dom is not updating class component when url change
- Updating react root component when its props change
- React test: after update input the props value still not change
More Query from same tag
- How can i create a list with React from nested objects?
- CreatedAt in MongoDB canĀ“t be sorted
- react TypeError: Cannot read property 'id' of undefined
- Redirecting doesn't render the component but changes url in address bar
- How to make TextField input wider?
- React toggle checkbox not toggling
- Refresh one child React component from form submit in sibling React component
- "Unknown word" error showing after adding postcss-loader
- How to upload files using React?
- How do I get data from a RESTful API JSON response in React?
- react-router-dom & material ui : forwardRef issue
- Unhandled Rejection (Error) (HttpError) when connecting to SignalR hub in Ocelot Api Gateway via React Client Application
- How to pass redux props to styled component in react typescript
- How can I synchronize the "scrollLeft" property of 2 divs while scrolling horizontally within a react component?
- How to use posts :title in url instead of :id in React.js
- React Draggable - How to remove border?
- How to implement pagination on frontend in ReactJS?
- jest enzyme reactJS - method executes regardless of return
- Dynamically building a render function in React
- xlsx is undefined when trying to export excel sheet
- React JS .map and assignment causing esLint error 'Assignment to property of function parameter. eslint(no param-reassign)'
- React: Calling setState within render method throws error
- React - Error: Invalid hook call. Hooks can only be called inside of the body of a function component. What is wrong my syntax?
- Building separate Stylesheets for different themes with webpack
- Call function after refetchQueries
- Explain this render prop in React
- Having Trouble getting this form to submit to netlify and the recaptcha to show
- Uncaught Error: Expected `onClick` listener to be a function, instead got a value of `object` type
- Using Next router to link to a dynamically created page
- webpack Resolve conflict? Should I use alias?