We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关键词:react 渲染性能调优
帮助开发者排查是哪个属性改变导致了组件的 rerender。
直接接受 ahooks 里面的一个方法: useWhyDidYouUpdate
源码实现:
import { useEffect, useRef } from "react"; export type IProps = Record<string, any>; export default function useWhyDidYouUpdate(componentName: string, props: IProps) { const prevProps = useRef<IProps>({}); useEffect(() => { if (prevProps.current) { const allKeys = Object.keys({ ...prevProps.current, ...props }); const changedProps: IProps = {}; allKeys.forEach((key) => { if (!Object.is(prevProps.current[key], props[key])) { changedProps[key] = { from: prevProps.current[key], to: props[key], }; } }); if (Object.keys(changedProps).length) { console.log("[why-did-you-update]", componentName, changedProps); } } prevProps.current = props; }); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
关键词:react 渲染性能调优
帮助开发者排查是哪个属性改变导致了组件的 rerender。
直接接受 ahooks 里面的一个方法: useWhyDidYouUpdate
源码实现:
The text was updated successfully, but these errors were encountered: