1.0.10 • Published 1 year ago

davlatov-state-manager v1.0.10

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

state-manager

Installation

npm install davlatov-state-manager

Basic Example

import { createStore, useSelector, useDispatch } from 'davlatov-state-manager';

const counterReducer = (state = { value: 0 }, action: Action) => {
  switch (action.type) {
    case 'counter/incremented':
      return { value: state.value + 1 }
    case 'counter/decremented':
      return { value: state.value - 1 }
    default:
      return state
  }
}

const store = createStore<ReturnType<typeof rootReducer>>(counterReducer);

const Counter: FC = () => {
  const count = useSelector((state) => state.value);
  const dispatch = useDispatch();

  const handleIncremented = () => {
    dispatch({ type: 'counter/incremented' });
  };

  const handleDecremented = () => {
    dispatch({ type: 'counter/decremented' });
  };

  return (
    <div>
      <button onClick={handleIncremented}>incremented</button>
      <p>{count}</p>
      <button onClick={handleDecremented}>decremented</button>
    </div>
  );
}
1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago