Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steverandy/react-create-context-provider
https://github.com/steverandy/react-create-context-provider
context react
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/steverandy/react-create-context-provider
- Owner: steverandy
- License: mit
- Created: 2019-02-17T12:58:32.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T16:29:59.000Z (almost 2 years ago)
- Last Synced: 2024-11-29T10:56:17.585Z (26 days ago)
- Topics: context, react
- Language: JavaScript
- Size: 448 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-create-context-provider
Create a React Context Provider component that allows updating Context value with Consumer or useContext.
## Install
```
$ npm install --save react-create-context-provider
```## Usage
``` javascript
import React from "react";
import ReactDOM from "react-dom";
import createContextProvider from "react-create-context-provider";let [AppContext, AppContextProvider] = createContextProvider({theme: "light"});
function DarkThemeButton() {
let {setTheme} = React.useContext(AppContext);
return setTheme("dark")}>Use Dark Theme;
}function App() {
let {theme} = React.useContext(AppContext);
return;
Theme: {theme}
}ReactDOM.render(
, document.body.getElementById("app"));
```## License
[MIT License](./LICENSE)