create-react-app React performance with SVG as ReactComponent and eslint with React.memo missing display name
See original GitHub issueI’m using this component in a create-react-app
app:
import { ReactComponent as ProfileIcon } from "./icons/profile.svg";
...
render(){
<ProfileIcon {...props}/>
}
Using also why-did-you-render
(https://github.com/welldone-software/why-did-you-render) I got this warning:
SvgProfileIcon
whyDidYouRender.min.js:1191 {SvgProfileIcon: ƒ} "Re-rendered because the props object itself changed but it's values are all equal." "This could of been avoided by making the component pure, or by preventing it's father from re-rendering." "more info at http://bit.ly/wdyr02"
whyDidYouRender.min.js:1191 prev props: {svgRef: null, className: "icon", height: "24", width: "24"} !== {svgRef: null, className: "icon", height: "24", width: "24"} :next props
So I made a custom PureComponent
like this:
import React from "react";
export default WrappedComponent =>
React.memo(props => <WrappedComponent {...props} />, () => true);
FIRST QUESTION: Is this performances-correct?
I’m using it like this:
import { ReactComponent as ProfileIcon } from "./icons/profile.svg";
import PureComponent from "./PureComponent";
const PureProfileIcon = PureComponent(ProfileIcon);
...
render(){
<PureProfileIcon {...props}/>
}
SECOND QUESTION: Can I avoid this component at all using React.memo (or something else) differently?
Now eslint is complaining about:
Component definition is missing display name eslint(react/display-name)
THIRD QUESTION: How can I fix this?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
React eslint error:Component definition is missing display ...
It's because you have eslint config which requries you to add displayName and propTypes. Do something like. const Child: React.
Read more >Component definition is missing display name in React
Set the `displayName` property on the component to fix the "Component definition is missing display name" error, e.g. `App.displayName = 'MyApp';`.
Read more >Top 10 Optimizing Techniques Every React developer should ...
I broke down the top ways to optimize your CRA React TS App into parts;. PureComponent and React.memo() — gain performance. Lazy loading...
Read more >ميډياويکي:Vector-opt-out - ويکيپېډيا
The Symbol used to tag the ReactElement-like types. If there is no native Symbol // nor polyfill, then a plain number is used...
Read more >List of top ReactJS Interview Questions & Answers
This reactProp (or whatever you came up with) name then becomes a property attached to React's native props object which originally already ...
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
Yes, that’s correct, the function passed as 2nd argument to useMemo() is usually called
areEqual
, thus it semantically makes sense to not re-render if areEqual returns true. See https://reactjs.org/docs/react-api.html#reactmemo for reference.You can fix the eslint/display-name with
but that rule is purely useful during development as production will have names minified anyways so.
@vzaidman, @ljosberinn thanks.