why did you render 排查 react 渲染情况

用于在开发环境跟踪 react 组件的渲染情况

https://github.com/welldone-software/why-did-you-render#readme

安装

npm install @welldone-software/why-did-you-render --save

开发环境启用渲染提示

import React from "react";

if (process.env.NODE_ENV === "development") {
  const whyDidYouRender = require("@welldone-software/why-did-you-render");
  whyDidYouRender(React, {
    trackAllPureComponents: false,
  });
}

引入即可

import "./wdyr";

某些组件不需要可以关闭:

export const ProjectListScreen = () => {
    // functional component
};

ProjectListScreen.whyDidYouRender = false;
本文收录于专栏
收集一些好用的前端开源库,主要是 npm 包