HeyThere
HeyThere

Reputation: 583

React Native bridge: send data continuously from native to JS?

I have read a bunch of resources online but didn't see any similar use case. I need to send data from native (Android) to JS continuously, with the data being small sized string.

Would this (from RN tutorial)

reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, data)

be the best way to do it? What if we need the message to be sent very frequently? Like every 100ms? Is there any other way to do it with better performance? How frequent can it go?

Thank you!

Upvotes: 1

Views: 1089

Answers (1)

Alexandre Nicolas
Alexandre Nicolas

Reputation: 1949

In react-native your javascript app is running on a different thread than you native application. I don't thinks there is a better way for sending data between the two threads than EventEmitter.

In the source code of libraries sending data frequently, EventEmitter is always used (example: react-native-sensors).

Upvotes: 1

Related Questions