I am making a react native app which receives data from ws api on callback.
This function resides in api module and look like this:
ws.onmessage = (e) => { //callbnack to HOME
const request = JSON.parse(e.data)
...
}
I want to show received text on screen in Component. It has state with text field, and <Text> {this.state.screenText} </Text>
element.
Both modules imported in Main screen component. How do I do this?
2
Answers
Use state management library like redux, zustand, etc. Here’s an example with zustand –
store.js
websocket.js
Main.js