nitroFetchOnWorklet() lets you run parsing/mapping off the JS thread using react-native-worklets.
import { nitroFetchOnWorklet } from 'react-native-nitro-fetch';
const map = (payload: { bodyString?: string }) => {
'worklet';
return JSON.parse(payload.bodyString ?? '{}');
};
const data = await nitroFetchOnWorklet('https://httpbin.org/get', undefined, map, { preferBytes: false });Options
preferBytes(defaultfalse): whentrue, sendsbodyBytesto the mapper; whenfalse, sendsbodyString.runtimeName: optional name for the created worklet runtime.
Notes
- Ensure
react-native-workletsis installed in your app to get off-thread execution.