|
|
|
|
|
by yiransheng
2748 days ago
|
|
Hooks reminds me of tensorflow scopes a little bit, in python: with tf.variable_scope("foo"):
with tf.variable_scope("bar"):
v = tf.get_variable("v", [1])
assert v.name == "foo/bar/v:0"
`v` tensor here will have a generated human readable unique name here: "foo/bar/v:0"It seems with hooks, react uses call order to derive the unique "leaf" hook id for runtime resolving its implementations. However, it would be nice if react hooks can automatically provide a similar human readable "hook id" (even if only for dev/debug build). function useWindowWidth() {
const [[width, setWidth], stateId] = debug(useState);
assert(stateId === "useWindowWidth/state/:0");
useEffect(() => { ... });
const [_, effId] = debug(useEffect, () => { ... });
assert(effId === 'useWindowWidth/effect/:1");
return width;
}
This will definitely help for nested custom hooks.. |
|
https://github.com/facebook/react/pull/14085