Skip to content

Context API #1

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

leopiccionia
Copy link

@leopiccionia leopiccionia commented Sep 27, 2020

This PR includes basic support to React-like Context API, including:

  • createContext
  • useContext
  • Context.Provider & Context.Consumer

This PR doesn't include:

  • Support for the (undocumented?) second parameter of createContext
  • Support for Class.contextType
  • Support for displayName1

At a quick look at React Aria source, I couldn't locate many references to Provider and Consumer as components. If you don't consider them useful, I could remove it.

I've implemented those functions using analogous provide/inject features present in Vue. The implementation supposes that contexts are created and consumed inside Vue.

1 It could be investigated in future. I don't know if Vue allows component's name as a getter.


I couldn't apply the patches and run the demo, so I couldn't test them against the React Aria codebase; therefore, I'm marking the PR as "draft".

For a running demo, see https://codepen.io/leopiccionia/pen/JjXzwON.

Copy link
Owner

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for sending a PR!

@leopiccionia leopiccionia marked this pull request as ready for review October 9, 2020 12:17
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.

2 participants