Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neonxp/compose
Simple provider compose for new React useContext Api, unstated-next or same.
https://github.com/neonxp/compose
Last synced: about 1 month ago
JSON representation
Simple provider compose for new React useContext Api, unstated-next or same.
- Host: GitHub
- URL: https://github.com/neonxp/compose
- Owner: neonxp
- Created: 2019-08-01T21:17:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-11-06T02:05:00.000Z (about 1 year ago)
- Last Synced: 2024-04-26T00:24:38.885Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 49.8 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# compose
Simple provider compose for new [React useContext Api](https://reactjs.org/docs/hooks-reference.html#usecontext), [unstated-next](https://github.com/jamiebuilds/unstated-next) or same.
## Usage
unstated-next:
```
import React, { useState } from 'react';
import { createContainer } from 'unstated-next';import { Compose } from 'provider-compose'; // <---
const useProvider1 = () => {
const [a, setA] = useState(0);
return { a, setA }
}const Provider1 = createContainer(useProvider1);
const ComponentA = (props) => {
const { a, setA } = Provider1.useContainer()
return setA(a + 1)}>A={a}
}
const useProvider2 = () => {
const [b, setB] = useState(0);
return { b, setB }
}const Provider2 = createContainer(useProvider2);
const ComponentB = (props) => {
const { b, setB } = Provider2.useContainer()
return setB(b + 1)}>B={b}
}const store = [Provider1.Provider, Provider2.Provider]; // <---
export default () => (
// <---
)
```