Reputation: 566
I am new in react native and facing a issue in passing data to the component.
having a component named WebSocket ,In this have multiple parameters to be accepted like below
const WebSocket = ({
socketUrl,
socketFirstRequest,
socketSecondRequest,
}) => {
// connecting socket and sending data to socket.
}
Now How to use this components at multiple places to send data to this component I tried this but not working like this.
const InstrumentList = () => {
// my request params for GC1_URL,socketFirstRequest,socketSecondRequest
return (
<View style={styles.container}>
{checkStatus === false && (
<WebSocketGC1
socketUrl={GC1_URL}
socketFirstRequest={socketFirstRequest}
socketSecondRequest={socketSecondRequest}
/>
)}
</View>
);
}
Upvotes: 0
Views: 78
Reputation: 3067
You don't need to react component for this functionality. React component useful if you render something on the UI side. From your implementation, I think you create a custom react hook. For example https://github.com/robtaussig/react-use-websocket or https://rossbulat.medium.com/react-hooks-managing-web-sockets-with-useeffect-and-usestate-2dfc30eeceec
Upvotes: 1