DEV Community

Nazmul Hasan👻
Nazmul Hasan👻

Posted on

ComponentDidUpdate is not firing !!!!!

I was updating a certain redux state in reducer like this,

case UPDATE_SOMETHING:
      return {
        ...state,
        something: action.something,
      };
Enter fullscreen mode Exit fullscreen mode

and i was checking the state update like following,

componentDidUpdate(prevProps, prevState) {
    const { something } = this.props;
    if (!_.isEqual(prevProps.something, something)) {
      this.setState({ something });
    }
  }
Enter fullscreen mode Exit fullscreen mode

But the problem is, i can see that my redux state is update in redux debugger, but componentDidUpdate is not firing anymore !!!!. After wondering for a while , i tried to update the redux state using shallow copy. Like this,

case UPDATE_SOMETHING:
      return {
        ...state,
        something: {
          ...state.something,
          ...action.something,
        },
      };
Enter fullscreen mode Exit fullscreen mode

Its, working now!!!!!!

Top comments (1)

Collapse
 
dance2die profile image
Sung M. Kim

That feeling when you dig it 🙂🤜