0 votes
in Programming by (580 points)

I am getting the above error when I try and use LD in my AppContext:

import LDClient from 'launchdarkly-react-native-client-sdk';
import { launchDarkly } from 'common/config';

    const bootstrapDarklyClient = async () => {
        const client = new LDClient();
        const clientConfig = {
            mobileKey: launchDarkly.key,
        };
        // need a user config for this to work. Just using a random string
        const userConfig = { key: 'xxx' };
        await client.configure(clientConfig, userConfig);
        return client;
    };

export default bootstrapDarklyClient;

AppContext:

const setRescueMeRedirectToWebFlag = async () => {
    try {
        const client = await bootstrapDarklyClient();
        const enabled = await client.boolVariation('enable-rescue-me-redirect-to-web', false);
        dispatch({ type: ENABLE_RESCUEME_REDIRECT_TO_WEB, value: enabled });
        client.close();
    } catch (e) {
        logger.error('Error occurred while getting launch darkly flag for `enable-rescue-me-redirect-to-web`', e);
    }
};

const setRescueMeRedirectunauthenticatedFlag = async () => {
    try {
        const client = await bootstrapDarklyClient();
        const enabled = await client.boolVariation('enable-rescue-me-redirect-unauthenticated', false);

        dispatch({
            type: ENABLE_RESCUEME_REDIRECT_UNAUTHENTICATED,
            value: enabled,
        });
        client.close();
    } catch (e) {
        logger.error('Error occurred while getting launch darkly flag for `enable-rescue-me-redirect-unauthenticated`', e);
    }
};

const setenableLiteRegistrationFlag = async () => {
    try {
        const client = await bootstrapDarklyClient();
        const enabled = await client.boolVariation('enable-lite-registration', false);
        dispatch({ type: ENABLE_LITE_REGISTRATION, value: enabled });
        client.close();
    } catch (e) {
        logger.error('Error occurred while getting launch darkly flag for `enable-lite-registration`', e);
    }
};

I am then using Async/await in my UseEffect hook:

React.useEffect(() => {
    const bootstrapAsync = async () => {
        try {
            dispatch({ type: APP_IS_LOADING, value: true });
            await setRescueMeRedirectToWebFlag();
            await setRescueMeRedirectunauthenticatedFlag();
            await setenableLiteRegistrationFlag();

Using:

"launchdarkly-react-native-client-sdk": "3.2.2", "react-native": "0.62.0",

Please log in or register to answer this question.

...