MCPcopy Create free account
hub / github.com/QuarkGluonPlasma/react-course-code / setState

Function setState

zustand-test/src/myZustand.js:7–22  ·  view source on GitHub ↗
(partial, replace)

Source from the content-addressed store, hash-verified

5 const listeners = new Set();
6
7 const setState = (partial, replace) => {
8 const nextState = typeof partial === 'function' ? partial(state) : partial
9
10 if (!Object.is(nextState, state)) {
11 const previousState = state;
12
13 if(!replace) {
14 state = (typeof nextState !== 'object' || nextState === null)
15 ? nextState
16 : Object.assign({}, state, nextState);
17 } else {
18 state = nextState;
19 }
20 listeners.forEach((listener) => listener(state, previousState));
21 }
22 }
23
24 const getState = () => state;
25

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected