How call React's setState function from outside of any component, like a utility function?

后端 未结 4 1521
忘了有多久
忘了有多久 2021-01-22 08:16

I have an app where I want to move the read, write operations to a utility file i.e. away from component. I am trying to do it this way.

component.js

imp         


        
4条回答
  •  一整个雨季
    2021-01-22 08:34

    It looks like you need to bind setState before passing it to an external function.

    saveData(this.setState.bind(this), data);

提交回复
热议问题