Skip to content

Why do contexts do this? #713

Answered by ryansolid
DaXcess asked this question in Q&A
Nov 5, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

The problem is probably here:

export const DiscordProvider: Component = ({ children }) => {

Destructuring children creates them outside the provider. Instead you should pass props. And access children under the provider.

export const DiscordProvider: Component = (props) => {
  ...
  return (
    <DiscordContext.Provider
      value={{
        authorize,
        logout,
        state,
        token: () => token,
        userinfo,
      }}
    >
      {props.children}
    </DiscordContext.Provider>
  );
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DaXcess
Comment options

Answer selected by DaXcess
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants