shalala
v0.2.1
Published
Easy state management for react using hooks in less than 1kb.
Downloads
8
Readme
shalala
Easy state management for react using hooks in less than 1kb.
Table of Contents
Install:
npm i shalala
or
yarn add shalala
Minimal example:
import React from 'react';
import { createState } from 'shalala';
const initialState = {
counter: 0,
};
const actions = {
increment: (store, amount) => {
return (state) => {
state.counter = state.counter + amount;
};
},
decrement: (store, amount) => {
return (state) => {
state.counter = state.counter - amount;
}
}
};
const useStore = createStore(initialState, actions);
const Counter = () => {
const [state, actions] = useStore();
return (
<div>
<p>
Counter:
{ state.counter }
</p>
<button type="button" onClick={() => actions.increment(1)}>
+1 to global
</button>
{ ' ' }
<button type="button" onClick={() => actions.decrement(1)}>
-1 to global
</button>
</div>
);
};
export default Counter