Simply Innovative
Simply Innovative

Reputation: 568

Creating Web Worker in React Native Android app

I am building a React Native android app. In app I want to download and parse huge amount of data from server. Since JavaScript is a single threaded language I don't want to execute this on same React Native JSC context. Is it possible to create a Web Worker inside React Native JSC context and do extensive background jobs?

I have tried to do the same, but it says function not available.

Upvotes: 13

Views: 11749

Answers (3)

lgxm3z
lgxm3z

Reputation: 21

Nowadays a library that tries to do something similar with JSI but that is not declared exactly as WebWorker is react-native-multithreading.

For now there is no solution within react-native but news may come in https://github.com/react-native-community/discussions-and-proposals/issues/486

Upvotes: 2

fgarci03
fgarci03

Reputation: 430

There is a library exactly for that now. Check out https://github.com/devfd/react-native-workers

Upvotes: 6

agenthunt
agenthunt

Reputation: 8678

AFAIK there is no WebWorker polyfill for React Native. You will probably have to write a Native Bridge Module. If you want to avoid that , check out this post where they use requestAnimationFrame to break heavy tasks. https://corbt.com/posts/2015/12/22/breaking-up-heavy-processing-in-react-native.html

Upvotes: 6

Related Questions