ReactJS SetState not rerendering ReactJS SetState not rerendering reactjs reactjs

ReactJS SetState not rerendering


Not sure if it is the core of your problem, but:

handleSetView={this.handleSetView}

is wrong, because how js binds this. Use:

handleSetView={this.handleSetView.bind(this)}

instead.

Also,

this.setState({  view: mode});console.log(this.state.view)

seems strange; note that this.state is not modified right after you call setState, it may took some time while React dispatches the scheduled setState operation. Put that console.log into render to see when it is actually called.

Finally, make sure, your components do not implement shouldComponentUpdate lifecycle method (you are probably not doing this explicitly, but if your component extends some class other than React.Component this may happen)


this is in the context of the react Component so either pass the reference of this to you function handleSetView or bind this as mentioned by @Tomas