[英]How do I find state of hooks in the state tree with React Dev Tools?
On this React page we have many hooks and many context providers.在这个 React 页面上,我们有许多钩子和许多上下文提供者。 One of the hooks I care about:我关心的钩子之一:
const { branchDetails, branchLoadError } = useBranchValidator();
Inside of it there's some state along with a couple of useEffect
s:在其中有一些状态以及几个useEffect
s:
const [branchId, setBranchId] = useState(queryParams.branchId ?? '');
I'd like to see the branchId
value with React Dev Tools.我想用 React Dev Tools 查看branchId
值。 I started with the assumption that the state for this hook would be inside the nearest context provider (image below) but it's not in there.我开始假设这个钩子的状态将在最近的上下文提供者中(下图),但它不在那里。
Is it possible to see the state in a React hook with the Dev Tools?是否可以使用开发工具查看 React 挂钩中的状态?
In the React Devtools sidebar, the hooks in use are displayed in a different section beneath the props , by default.在 React Devtools 侧边栏中,使用中的钩子默认显示在props下方的不同部分中。
They are not displayed with their assigned variable names in React DevTools, but which state value they are is usually inferable from context.在 React DevTools 中,它们不会与分配的变量名称一起显示,但通常可以从上下文中推断出它们的状态值。 As per React Dev Tools does not show Component Names or State Variable Names , clicking on the magic wand icon in the top right of the hooks section can display this information, but it can be resource-intensive and result in timeouts when used on complex components like context providers, in my personal experience.根据React Dev Tools 不显示 Component Names 或 State Variable Names ,单击hooks部分右上角的魔术棒图标可以显示此信息,但它可能会占用资源并导致在复杂组件上使用时超时根据我的个人经验,就像上下文提供者一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.