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


Related Query

More Query from same tag