React re-write componentWillReceiveProps in useEffect

后端 未结 4 1471
情话喂你
情话喂你 2020-12-18 13:47

So I am re-writing a component with hooks, and I ran into an interesting challenge, I need to mimick some old behaviour of componentWillReceiveProps with the

4条回答
  •  难免孤独
    2020-12-18 14:27

    With the current logic, you want to fire a side-effect only on lateMinutes[${bookingId}].value change:

    const Component = props => {
      useEffect(() => {
        console.log('prop lateMinutes changed');
        // ...
      }, [props[`lateMinutes[${bookingId}].value`]);
      return ...
    };
    

提交回复
热议问题