I need to use current props and previous props value in my React component. So i did it like this
state = { current: null, previous: null, }; componentWillReceiveProps(nextProps) { if (nextProps.amount !== this.state.current) { this.setState({previous: this.state.current, current: nextProps.amount}); } } ... render() { const {previous, current} = this.state; return ( ... <CountUp className="counter" start={previous} end={current} duration={1}/> ... ) } It works fine, but is it good React practise to do it like this? Are there others "good" ways to do it?
setState(prevState)is provided by React along withpropsboth of which are optional.