boriii
boriii

Reputation: 87

Converting componentWillReceiveProps

 componentWillReceiveProps(nextProps) {
    if (this.props.active !== nextProps.active) {
      Animated.timing(this._active, {
        duration: 300,
        easing: Easing.bounce,
        toValue: Number(nextProps.active),
      }).start();
    }
  }

This is the code of react-native-sortable-list. And what I am trying to do is change this code with react-hook

Is there any help can I get to change componentWillReceiveProps part to functional component?

Upvotes: 0

Views: 64

Answers (1)

Sayog
Sayog

Reputation: 770

You can use useEffect with dependency list. when props.active changes component will rerender

useEffect(()=>{
    Animated.timing(props.active, {
        duration: 300,
        easing: Easing.bounce,
        toValue: Number(props.active),
      }).start();
},[props.active])

Upvotes: 1

Related Questions