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.

Doesn't work as expected with React.memo

See original GitHub issue

When I try to wrap a functional component with React.memo I get <[object Object] /> instead of the component name.

The output without React.memo is:

Storybook - Google Chrome without React.memo

The output with React.memo is:

Storybook - Google Chrome with React.memo

storiesOf('My component', module)
  .addDecorator(jsxDecorator)
  .add('default', () => (
    <MyComponent>
      <span>Some text content</span>
    </MyComponent>
  ));
  • react: 16.8.6
  • storybook: 5.1.11
  • storybook-addon-jsx: 7.1.6

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
hipstersmoothiecommented, Mar 26, 2020

Try

const MyComponent = (props) =><MyComponentMemo {...props} />; 
MyComponent.displayName = 'MyComponent'

I’ve been meaning to toy around with writing a better displayName babel plugin, but until then manually setting the name works pretty well. NOTE: This can also be easily overriden

3reactions
semihraifgurelcommented, Jan 20, 2021
Ekran Resmi 2021-01-20 21 16 53 I used it like this to solve my work.
Read more comments on GitHub >

github_iconTop Results From Across the Web

React.memo isn't working - what am I missing? - Stack Overflow
I'm obviously missing something here or don't quite understand how this works. This component is a few levels down, but it passes in...
Read more >
How to use React.memo() to improve performance
The reason React.memo doesn't work anymore is because it only does a shallow comparison of the component's properties.
Read more >
memo - React Docs
With memo , you can create a component that React will not re-render when its parent re-renders so long as its new props...
Read more >
Use React.memo() wisely
You gain a performance boost: by reusing the memoized content, React skips rendering the component and doesn't perform a virtual DOM difference ...
Read more >
When should you use React.memo and useMemo?
useMemo is a hook that gets run during the render stage and also ... Example 5 // WRONG, does not work as expected...
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