How to use the easy-peasy.useDispatch function in easy-peasy

To help you get started, we’ve selected a few easy-peasy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ctrlplusb / easy-peasy / src / __tests__ / typescript / implementation.tsx View on Github external
function MyComponent() {
  const token = useStore((state: State) => state.user.token);
  const { login } = useActions((dispatch: Actions) => ({
    login: dispatch.user.login,
  }));
  const { addTodo } = useActions((actions: Actions) => ({
    addTodo: actions.todos.addTodo,
  }));
  addTodo('Install easy peasy');
  const dispatch = useDispatch();
  dispatch({
    type: 'ADD_FOO',
    payload: 'bar',
  });
  return (
    <button> login({ username: 'foo', password: 'bar' })}&gt;
      {token || 'Log in'}
    </button>
  );
}