* Get a hook's state from the currentComponent * @param {number} index The index of the hook to get * @param {number} type The index of the hook to get * @returns {any}
(index, type)
| 137 | * @returns {any} |
| 138 | */ |
| 139 | function getHookState(index, type) { |
| 140 | if (options._hook) { |
| 141 | options._hook(currentComponent, index, currentHook || type); |
| 142 | } |
| 143 | currentHook = 0; |
| 144 | |
| 145 | // Largely inspired by: |
| 146 | // * https://github.com/michael-klein/funcy.js/blob/f6be73468e6ec46b0ff5aa3cc4c9baf72a29025a/src/hooks/core_hooks.mjs |
| 147 | // * https://github.com/michael-klein/funcy.js/blob/650beaa58c43c33a74820a3c98b3c7079cf2e333/src/renderer.mjs |
| 148 | // Other implementations to look at: |
| 149 | // * https://codesandbox.io/s/mnox05qp8 |
| 150 | const hooks = |
| 151 | currentComponent.__hooks || |
| 152 | (currentComponent.__hooks = { |
| 153 | _list: [], |
| 154 | _pendingEffects: [] |
| 155 | }); |
| 156 | |
| 157 | if (index >= hooks._list.length) { |
| 158 | hooks._list.push({}); |
| 159 | } |
| 160 | |
| 161 | return hooks._list[index]; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * @template {unknown} S |
no test coverage detected
searching dependent graphs…