Skip to content

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