im trying to set up usereducer and i want to be able to flip the state of hasStarted (a boolean). im new to typescript and cant seem to figure out how to correctly implement it. here's my code (theres probably all sorts of things wrong with this code, sory)
import React from "react";
const ACTIONS = {
FLIP: "flipHasStarted"
}
type State = {
hasStarted: boolean;
};
type Action = {
type: "flip";
};
const reducer = (state: State, action: Action) => {
switch (action.type) {
case ACTIONS.FLIP:
return {...state, hasStarted: !hasStarted}
}
return state;
};
const initialState = {
hasStarted: false,
};
export const App = () => {
const [state, dispatch] = React.useReducer(reducer, initialState);
return (
<>
<button onClick={() => dispatch(flipHasStarted)} className="bg-yellow-500 p-8">
TEST
</button>
</>
);
};