Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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)