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

Report React contexts #53

Closed
IgorAufricht opened this issue Oct 21, 2024 · 1 comment · Fixed by #54
Closed

Report React contexts #53

IgorAufricht opened this issue Oct 21, 2024 · 1 comment · Fixed by #54
Labels
enhancement New feature or request

Comments

@IgorAufricht
Copy link
Contributor

As a convention, React contexts usually start with a capital letter, e.g. MyContext. This means the plugin considers them a component and not report them, which is not ideal, as they still break HMR.

Example:

export const hello = "world";  // reported correctly
export const Component = () => <div>My component</div>;
export const MyContext = createContext("hello");  // not reported
export const Component = () => <div>Component</div>;

It would be really good if the plugin could report these cases (probably with a new config option). I can think of two potential ways to detect React contexts:

  • Naming convention only - if the name starts with an capital letter and ends with Context
  • A constant starting with a capital letter that calls createContext

Either one or a combination of both could be used.

Let me know what you think - if you agree this would be a good addition, I could also create a PR.

Thanks!

@ArnaudBarre
Copy link
Owner

That's a good point!
I think Context is a bit too generic, so the naming convention will also trigger for people creating component like a context for a chat component that will be called ChatContext but actually be a UI sidebar or a header.

Handling the simple case for now export const MyContext = createContext("hello"); is not too hard to add so you can try to do a PR for it!

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

Successfully merging a pull request may close this issue.

2 participants