Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useContext doesn't get value in dev mode #2365

Open
geohuz opened this issue Nov 15, 2024 · 0 comments
Open

useContext doesn't get value in dev mode #2365

geohuz opened this issue Nov 15, 2024 · 0 comments

Comments

@geohuz
Copy link

geohuz commented Nov 15, 2024

Describe the bug

the useContext get null value in dev mode. According to the documentation:

Your Example Website or App

https://stackblitz.com/edit/solidjs-templates-c5vdbu?file=src%2FContext.jsx

Basically I have a error handler to check for the default value of the context in hooks.jsx, like this:

export function useCounter() {
  const value = useContext(CounterContext);
  if (!value) {
    throw new Error(
      "useCounter must be used within a CounterContext.Provider ",
    );
  }
  return value;
}

Steps to Reproduce the Bug or Issue

Change the source code, (eg. comment) in the context.jsx then the error:

Uncaught (in promise) Error: useCounter must be used within a CounterContext.Provider 
    at useCounter (hooks.jsx:7:11)
....

appears in the console. Have to refresh the page to remove the error.

Expected behavior

The error shouldn't appear in dev mode.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant