diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-08-02 01:06:42 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-08-02 01:06:42 +0300 |
commit | 57d33c179d9964c207d6d6928fbed07c74ebba14 (patch) | |
tree | eafdf427d8ce96030fd8892d119031517fea62c2 | |
parent | 93d2c42770e3a28fde093298e5b1dda8d5aad4ca (diff) |
Added readme
-rw-r--r-- | package.json | 5 | ||||
-rw-r--r-- | readme.md | 44 |
2 files changed, 47 insertions, 2 deletions
diff --git a/package.json b/package.json index 984ecb9..8c8f701 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unstated-next-compose", - "version": "0.0.3", + "version": "0.0.4", "description": "Simple compose provider for unstated-next", "main": "dist/compose.js", "umd:main": "dist/compose.umd.js", @@ -31,6 +31,7 @@ "microbundle": "^0.11.0" }, "peerDependencies": { - "react": "^16.8.6" + "react": "^16.8.6", + "unstated-next": "^1.1.0" } } diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..43665c5 --- /dev/null +++ b/readme.md @@ -0,0 +1,44 @@ +# unstated-next-compose + +Simple provider compose for [unstated-next](https://github.com/jamiebuilds/unstated-next) + +## Usage + +``` +import React, { useState } from 'react'; +import { createContainer } from 'unstated-next'; + +import { Compose } from 'unstated-next-compose'; // <--- + +const useProvider1 = () => { + const [a, setA] = useState(0); + return { a, setA } +} + +const Provider1 = createContainer(useProvider1); + +const ComponentA = (props) => { + const { a, setA } = Provider1.useContainer() + return <button onClick={() => setA(a + 1)}>A={a}</button> +} +const useProvider2 = () => { + const [b, setB] = useState(0); + return { b, setB } +} + +const Provider2 = createContainer(useProvider2); + +const ComponentB = (props) => { + const { b, setB } = Provider2.useContainer() + return <button onClick={() => setB(b + 1)}>B={b}</button> +} + +const store = [Provider1.Provider, Provider2.Provider]; // <--- + +export default () => ( + <Compose providers={store}> // <--- + <ComponentA /> + <ComponentB /> + </Compose> +) +```
\ No newline at end of file |