hooco
v1.1.11
Published
hooco.js
Downloads
6
Readme
hooco
React hooks & contextual API for apps binding.
import hooco from 'hooco'
export function Counter(state) {
const {counter = 0} = state();
function inc() {
state({counter: counter + 1})
}
return {
counter,
inc
};
}
export const {
use: useCounter,
Provider: CounterProvider,
Consumer: CounterConsumer,
} = hooco(Counter)
/// ----
function App() {
const {counter, inc} = useCounter();
return <div>
<h2>Counter: {counter}</h2>
<button onClick={inc}>inc</button>
</div>
}