0.2.1 • Published 2 years ago

shalala v0.2.1

Weekly downloads
1
License
MIT
Repository
-
Last release
2 years ago

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
0.2.1

2 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago