Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Alert machine for xState
import { Machine, assign } from "xstate";
const initialState = {
alert: {},
};
export default Machine(
{
id: "alert",
initial: "idle",
context: {
...initialState,
},
states: {
idle: {
entry: "resetState",
on: {
ALERT: "active",
},
},
active: {
entry: "assignAlert",
on: {
CLEAR: "idle",
},
},
},
},
{
actions: {
assignAlert: assign({
alert: (context, event) => event?.alert,
}),
resetState: assign({
...initialState,
}),
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment