监控内部状态
该库内部通过状态机跟踪所有已分析的屏幕。虽然在生产环境中你不需要这样做,但在开发时获取这些状态机转换的转储可能有助于调试。你可以通过以下方式做到这一点:
tsx
const StateLogger = () => {const state = useProfilerState({// optional. Defaults to every profiled screendestinationScreen: new RegExp('^Home.*$'),});useEffect(() => {console.log('State:', JSON.stringify(state));}, [state]);};
tsx
const StateLogger = () => {const state = useProfilerState({// optional. Defaults to every profiled screendestinationScreen: new RegExp('^Home.*$'),});useEffect(() => {console.log('State:', JSON.stringify(state));}, [state]);};
请注意,useProfilerState
hook - 就像所有其他性能分析器 TypeScript API 一样 - 必须作为 PerformanceProfiler
组件的子组件渲染。