Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
Context returns undefined functions on any refresh in React Native App

I have an issue on any app refresh, ONE of my Contexts is returning undefined functions.

I have the following structure:

export default function AppWrapper() {
    return (
        <GlobalProvider>
            <ChildProvider>
                <App />
            </ChildProvider>
        </GlobalProvider>
    );
}

I am getting undefined on functions from ChildProvider, which looks like this:

const INITIAL_STATE = {
    orders: [],
    error: null,
};

const ChildContext = React.createContext({ ...INITIAL_STATE });
const ChildConsumer = ChildContext.Consumer;

const OrderProvider = (props) => {
    const { children } = props;
    const { store, userId } = useContext(GlobalContext);

    const [state, setState] = React.useReducer((state, newState) => {
        const combinedState = { ...state, ...newState };
        return combinedState;
    }, INITIAL_STATE);

    const getDataFromStore = async () => {
        if (store?.id) {
            try {
                const { error, data } = await getOrdersByStore({store.id});
                if (data) {
                    const data1 = <iterating through data>;

                    await setState({ orders: data1 });
                } else {
                    await setState({ error: error });
                }
            } catch (e) {
                await setState({ error: e });
            }
        }
    };

  
    const actions = { getDataFromStore};
    return <ChildContext.Provider value={{ ...state, ...actions }}>{children}</ChildContext.Provider>;
};

export { ChildContext, ChildConsumer, ChildProvider };


And in Home.js, I call these functions as such:

const { getDataFromStore } = useContext(ChildContext)

useEffect(() => {

        const getOrders = async () => {
            store?.name && (await getDataFromStore());
        };
        getOrders();
    }, [store]);

And in Home.js is where that function (and any function defined in ChildContext) is undefined on any refresh.

Some Details:

  • It is not a spelling error, or 'can't find file' error.
  • The only thing I am currently storing in session is the auth token.
  • Everything from state is defined (even if in its INITIAL_STATE form)
  • Wherever I call the undefined function, I use async/await
  • I do not actually use the Consumer anywhere
  • The AppWrapper, GlobalContext and ChildContext are all nested inside a context folder. App.js is in the root directory.
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!