This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import useMutableReducer from "./useMutableReducer"; | |
| const reducer = (draft, action, state) => { | |
| switch (action) { | |
| case "increment": | |
| draft.count++; | |
| break; | |
| case "decrement": | |
| draft.count--; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const {useCallback, useEffect, useReducer, useRef} = require('react'); | |
| let effectCapture = null; | |
| exports.useReducerWithEmitEffect = function(reducer, initialArg, init) { | |
| let updateCounter = useRef(0); | |
| let wrappedReducer = useCallback(function(oldWrappedState, action) { | |
| effectCapture = []; | |
| try { | |
| let newState = reducer(oldWrappedState.state, action.action); |
OlderNewer