diegohaz / constate

React Context + State

Home Page:https://codesandbox.io/s/github/diegohaz/constate/tree/master/examples/counter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warning about Component not wrapped within a provider

CoinCoderBuffalo opened this issue · comments

commented

My main app looks like this, and there are 2 constate providers: NotificationProvider, MessageProvider.

return (
      <UserProvider>
        <NotificationProvider>
          <MessageProvider>
            <MenuProvider>
              <View style={styles.container}>
                {Platform.OS === 'ios' && <StatusBar barStyle="default" />}
                <AppNavigator />
              </View>
            </MenuProvider>
          </MessageProvider>
        </NotificationProvider>
      </UserProvider>
    );

On component screens, I am using constate hooks like this:

import { useMessageContext } from "../../context/MessageContext";
const { count } = useMessageContext();

Everything is working fine, but why do I see the warning?

commented

Can you create a reproduction on CodeSandbox please? If it’s not possible, please paste the entire file contents together with the warning stack.

A common mistake that generates this error is putting the context hook in the same component as you use the Provider. But you’re saying that everything is working fine, so this might not be your problem.

I'm getting this warning as part of an enzyme test

commented

@gone That means you’re not wrapping your test components with the Provider component.

commented

Closing as I can't reproduce the original issue. If you provide a repro I'll re-open it.