How to check if a component is mounted in React-Native ES6

后端 未结 2 1238
终归单人心
终归单人心 2021-02-11 22:08

I am setting a listener in my application and using force update whenever it is broadcasted but it gives error forceUpdate cant be called on unmounted component. How can I check

2条回答
  •  迷失自我
    2021-02-11 22:50

    Using ReactUpdateQueue, you can avoid managing your own isMounted state.

    const ReactUpdateQueue = require('ReactUpdateQueue');
    
    // Pass the ref to your component.
    if (ReactUpdateQueue.isMounted(view)) {
      // Your component is mounted!
    }
    

提交回复
热议问题