(initialState)
| 205 | } |
| 206 | |
| 207 | function useState(initialState) { |
| 208 | const currentFiber = wipFiber; |
| 209 | |
| 210 | const oldHook = wipFiber.alternate?.stateHooks[stateHookIndex]; |
| 211 | |
| 212 | const stateHook = { |
| 213 | state: oldHook ? oldHook.state : initialState, |
| 214 | queue: oldHook ? oldHook.queue : [], |
| 215 | }; |
| 216 | |
| 217 | stateHook.queue.forEach((action) => { |
| 218 | stateHook.state = action(stateHook.state); |
| 219 | }); |
| 220 | |
| 221 | stateHook.queue = []; |
| 222 | |
| 223 | stateHookIndex++; |
| 224 | wipFiber.stateHooks.push(stateHook); |
| 225 | |
| 226 | function setState(action) { |
| 227 | const isFunction = typeof action === "function"; |
| 228 | |
| 229 | stateHook.queue.push(isFunction ? action : () => action); |
| 230 | |
| 231 | wipRoot = { |
| 232 | ...currentFiber, |
| 233 | alternate: currentFiber, |
| 234 | }; |
| 235 | nextUnitOfWork = wipRoot; |
| 236 | } |
| 237 | |
| 238 | return [stateHook.state, setState]; |
| 239 | } |
| 240 | |
| 241 | function useEffect(callback, deps) { |
| 242 | const effectHook = { |
no outgoing calls
no test coverage detected