question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

create-react-app React performance with SVG as ReactComponent and eslint with React.memo missing display name

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
ljosberinncommented, May 1, 2019

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

const PureProfileIcon = PureComponent(ProfileIcon);
PureProfileIcon.displayName = 'PureProfileIcon';

but that rule is purely useful during development as production will have names minified anyways so.

0reactions
frederikhorscommented, May 2, 2019
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found