Skip to content

Support being reducer function passed to React’s useReducer accepting an event as action #32

Description

@royalicing
function reducer(previousState: State, event: React.FormEvent<HTMLFormElement> | React.MouseEvent<HTMLButtonElement>): State {
  return previousState.machine.next(event);
}

eventsReducer(machine)

It wouldn’t support side effects and listening/emitting to events (e.g. with listenTo()).

import { eventsReducer } from 'yieldmachine';

function useMachine(machine) {
  const [state, dispatch] = useReducer(eventsReducer(machine));
  return [state, dispatch];
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions