eager-pizza-76165
02/27/2023, 11:11 PMnon-std C++ exception. When I uncomment the await rudderClient.setup(…) call, the app starts normally.millions-activity-52391
02/27/2023, 11:11 PMeager-pizza-76165
02/27/2023, 11:12 PMcalm-yak-10773
02/28/2023, 8:12 AM"strict": true, as you mentioned in the previous thread?
the type error is only present with theOnce you turn that off, does this issue still occur?option in"strict": truetsconfig.json
eager-pizza-76165
02/28/2023, 8:13 AM"strict": true, it doesn’t seem related and is blockingeager-pizza-76165
02/28/2023, 8:14 AMcalm-yak-10773
02/28/2023, 8:22 AMeager-pizza-76165
02/28/2023, 8:25 AMeager-pizza-76165
02/28/2023, 8:37 AMawait keyword allows the app to run. I do have "module": "esnext", in tsconfig.json, not sure what else is required… This might be a React Native or project setup issue.calm-yak-10773
02/28/2023, 8:54 AMeager-pizza-76165
02/28/2023, 8:59 AMeager-pizza-76165
02/28/2023, 9:07 AMuseEffect 🤔 https://github.com/rudderlabs/rudder-sdk-react-native/blob/develop/apps/example/src/app/App.tsx#L125eager-pizza-76165
02/28/2023, 9:09 AMawait keyword, or actually worse, at it’s called only after the first render of the app… It would be nice if you had an example that actually implements the setup commands and recommendations from the docs exactly.calm-yak-10773
02/28/2023, 11:20 AMeager-pizza-76165
02/28/2023, 11:23 AMcalm-yak-10773
02/28/2023, 12:27 PMany initial events.
The code snippet mentioned in our documentation was intended to be used as part of an asynchronous function:
await rudderClient.setup(WRITE_KEY, {
dataPlaneUrl: DATA_PLANE_URL,
trackAppLifecycleEvents: true,
recordScreenViews: true,
})
We apologize for the trouble you faced while referring to our documentation. We will improve the documentation by including both ways to initialize the SDK, i.e., using useEffect and using top-level await.
Meanwhile please refer to below steps to initialise the React-Native SDK using top level await (in case you intend not to initialise the SDK using useEffects):
• Create any file (say rudderinit.ts)
• Copy the following code snippet in above file:
import rc, {RUDDER_LOG_LEVEL} from '@rudderstack/rudder-sdk-react-native';
const initRudder = async () => {
const config = {
dataPlaneUrl: '<DATA_PLANE_URL>',
trackAppLifecycleEvents: true,
autoCollectAdvertId: true,
recordScreenViews: true,
logLevel: RUDDER_LOG_LEVEL.VERBOSE,
};
await rc.setup('<WRITE_KEY>', config);
};
export {initRudder};
• In your index.js file paste this snippet:
import {initRudder} from './rudderinit';
try {
initRudder();
} catch (e) {
console.log(e);
}
• Before the AppRegistry.registerComponent(..); mount the root component.
Regarding the useEffect hook, it is expected to work similarly to top level await.
What happens if it’s not done as suggested?• I think it can be used according to your preference, if you have any specific requirements or preferences, please let us know.
eager-pizza-76165
02/28/2023, 12:34 PMuseEffect approach is surely enough.eager-pizza-76165
02/28/2023, 12:40 PMcalm-yak-10773
02/28/2023, 2:28 PM