06.useReducer源码实现
hooks.js
js
export function useReducer(reducer, initialValue) {
states[hookIndex] = states[hookIndex] || initialValue;
const currentIndex = hookIndex;
function dispatch(action) {
states[currentIndex] = reducer(states[currentIndex], action);;
emitUpdateForHooks();
}
return [states[hookIndex++], dispatch];
}