1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| export const TableContext = createContext({ tableData: [], halted: true, dispatch: () => {}, });
const Minesweeper = () => { const [state, dispatch] = useReducer(reducer, initialState); const value = useMemo(() => ({ tableData: state.tableData, dispatch }), [ state.tableData, ]); return ( <TableContext.Provider value={value}> <Form /> <div>{timer}</div> <Table /> <div>{result}</div> </TableContext.Provider> ); };
const onClickBtn = userCallback(() => { dispatch({ type: START_GAME, row, cell, mine }); }, [row, cell, mine]);
|