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

feat(graphiql-react): add useTheme to context #2971

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matijagaspar
Copy link

Fixes #2956

Makes useTheme a context instead of local state so it can be used in plugins (or any children of <GraphiQL/>) when using:

const {theme, setTheme} = useTheme()

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2022

🦋 Changeset detected

Latest commit: f0ac054

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
graphiql Minor
@graphiql/react Minor
@graphiql/plugin-explorer Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 12, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: matijagaspar / name: Matija Gašpar (1a0ba35)

@jonathanawesome
Copy link
Collaborator

jonathanawesome commented Dec 19, 2022

It would be great to get the return values updated as well, see suggestion here.

Also, would love to see some tests for this new functionality.

@matijagaspar matijagaspar force-pushed the feat(graphiql-react)/add-theme-to-context branch from 1a0ba35 to fc92aae Compare January 5, 2023 08:56
);
}

export const useTheme = createContextHook(ThemeContext);
Copy link
Member

@acao acao Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a documentation block above, for the api docs? annotations will automatically be inferred, just for the description

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@matijagaspar matijagaspar force-pushed the feat(graphiql-react)/add-theme-to-context branch from fc92aae to e85399a Compare January 17, 2023 15:59
@matijagaspar matijagaspar force-pushed the feat(graphiql-react)/add-theme-to-context branch from e85399a to f0ac054 Compare January 17, 2023 16:01
@acao
Copy link
Member

acao commented Feb 19, 2023

@thomasheyenbrock and @jonathanawesome - should we ask for tests for this?

Copy link
Collaborator

@thomasheyenbrock thomasheyenbrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @matijagaspar, that's an awesome addition!

Starting to add some tests to this would be awesome, but I wouldn't put that on @matijagaspar - unless you're up to it!

type ThemeContextProviderProps = { children: ReactNode };

export function ThemeContextProvider(props: ThemeContextProviderProps) {
const theme = useThemeInternal();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We could just inline the contents from that hook here and avoid the extra function.

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

Successfully merging this pull request may close these issues.

[graphiql/react] useTheme hook does not update when user changes the theme
4 participants