@flowrrs/create-context
v0.0.11
Published
Simple utility to create context-bound React hooks.
Downloads
2
Readme
@flowrrs/create-context
Simple utility to create context-bound React hooks.
Install
npm install --save @flowrrs/create-context
Usage
import * as React from 'react'
import { createContextHook } from '@flowrrs/create-context'
const [FooProvider, useFooStore, FooContext] = createContextHook((providerProps) => {
const [foo, setFoo] = React.useState('foo' + providerProps.suffix)
return { foo, setFoo }
})
const App = () => {
return (
<FooProvider suffix="bar">
<InnerApp />
</FooProvider>
)
}
const InnerApp = () => {
const { foo, setFoo } = useFooStore()
return (
<div>
<h1>{foo}</h1>
<button onClick={() => setFoo(foo.toUpperCase())}>
uppercase foo
</button>
</div>
)
}
License
MIT © flowrrs
This package was created using create-react-hook.