React中利用shouldComponentUpdate解决componentDidUpdate渲染数据问题

294 阅读1分钟
<script>
shouldComponentUpdate(nextProps, nextState) {
    return nextState.data !== this.state.data;
  }

componentDidUpdate
  componentDidUpdate(prevProps) {
    if (prevProps.value !== this.props.value && this.props.value) {
      getBase64(this.props.value, imageUrl =>
        this.setState({
          imageUrl,
        }),
      );
    }
  }
 </script>