React setState不触发render更新

2019-11-26  本文已影响0人  狂奔的大蜗牛

下面这种写法不会触发render更新

      this.setState((state) => {
        state.startSearchKey = value;
        this.goSearch();
      });

原因是:出现了浅比较,不触发render生命周期
下面是正确的写法

      this.setState({
        startSearchKey: value
      }, () => {
        this.goSearch();
      });

参考链接:
https://www.cnblogs.com/soyxiaobi/p/10065003.html

上一篇 下一篇

猜你喜欢

热点阅读