首页 > 解决方案 > 如果调用另一个组件的套接字函数,则在屏幕区域执行行。-React-Native

问题描述

我有一个外部套接字功能

export default class SocketInstance
{
   static getSocketInstance()
   {
       ...
   }
   
   ...

   listen(aState)
   {
      ...
      return !aState
   }
}

然后在我的屏幕区域

从 '.../...' 导入 SocketInstance;

export default class screenArea extends Component
{  
   screenArea()
   {
       this.state={
         theState: false
       }
   }   

   render()
   {
       return(....)
   }

   componentDidMount()
   {
       this.socket = SocketInstance.getSocketInstance();
       const getReturningState = this.socket.listen(this.state.theState)
       console.warn(getReturningState)  //Only print initially but not after the listen is triggered
   }
}

为简单起见,有没有办法在触发 get listen 后获取 screenArea 中打印的状态?再次为简单起见,我使用的是 print,但我需要在 screenArea 中执行其他操作。

标签: javascriptreactjsreact-native

解决方案


推荐阅读