How to use in CRA(5.0.0) React17.0.1
See original GitHub issueI tried a lot of ways,but it dosen’t show any information in console. I don’t know what’s wrong.
import { times } from "lodash";
import React from "react";
import ReactDOM from "react-dom";
import whyDidYouRender from "@welldone-software/why-did-you-render";
if (process.env.NODE_ENV === 'development') {
const whyDidYouRender = require('@welldone-software/why-did-you-render');
whyDidYouRender(React, {
trackAllPureComponents: true,
});
}
class BigListPureComponent extends React.PureComponent {
static whyDidYouRender = true;
render() {
console.log(
"BigListPureComponent Re-Render! - We don't want to get here too often."
);
return (
<div style={this.props.style}>
<h2>BigListPureComponent</h2>
<div>
{times(3000).map((n) => (
<div key={n}>Element #{n}</div>
))}
</div>
</div>
);
}
}
const bigListStyle = { width: "100%" }; // eslint-disable-line no-unused-vars
// Notice, that unlike the huge list, we don't track Main's re-renders because we don't care about it's re-renders.
class Main extends React.Component {
state = { count: 0 };
render() {
return (
<div
style={{
height: "100%",
width: "100%",
display: "flex",
flexDirection: "column"
}}
>
<h1>Big List (Main Demo)</h1>
<p>
{
'Open the console and notice how the heavy list re-renders on every click on "Increase!" even though it\'s props are the same.'
}
</p>
<div>
<button
onClick={() => {
this.setState({ count: this.state.count + 1 });
}}
>
Increase!
</button>
</div>
<div>
<span>Count: {this.state.count}</span>
</div>
<BigListPureComponent style={{ width: "100%" }} />
<BigListPureComponent />
</div>
);
}
}
ReactDOM.render(<Main />, document.getElementById("root"));
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:12
Top Results From Across the Web
A leap forward in 3D printing with Ultimaker Cura 5.0
A huge new release from Ultimaker Cura is finally here with version 5.0! Get ready to jump into a whole new world of...
Read more >Introducing Ultimaker Cura v5.0 - A big step ... - YouTube
Ultimaker Cura introduces an entirely new slicing engine that offers higher-quality, stronger printed parts with significantly reduced ...
Read more >node packages | Corvid by Wix
react -native-smtp-mailer. 1.2.5. available. 12/28/2022. requestor. 0.1.1. available ... 5.0.0. available. 12/15/2022. axios. 1.2.1. available. 12/15/2022.
Read more >Cura Settings Decoded – An Ultimaker Cura Tutorial - All3DP
Discover the hidden features of the Cura slicer software. We'll show you how to take your 3D printing to the next level for...
Read more >Breakthrough in 3D printing with Ultimaker Cura 5.0 beta
With this release, all Ultimaker Cura users can expect increased print ... These models were sliced using a layer height of 0.1mm and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The discussion on CRA 4 is here: #154. I’ll try to look at CRA 5 this week.
This works for react-scripts@5.0.0, react-app-rewired@2.2.1, and customize-cra@1.0.0. Probably, If you use another way of modifying CRA then the logic of changing ‘babel-preset-react-app’ is identical.