Skip to content

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

@RoyalIcing

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];
}

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