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.

TypeError: Cannot read property 'props' of null

See original GitHub issue

Hello!

I tried to create dynamically accordion with condition.

But I got an ERROR:

accordion.js?96e3:69 Uncaught TypeError: Cannot read property ‘props’ of null at eval (accordion.js?96e3:69) at mapSingleChildIntoContext (react.development.js?99ee:914) at traverseAllChildrenImpl (react.development.js?99ee:787) at traverseAllChildrenImpl (react.development.js?99ee:803) at traverseAllChildren (react.development.js?99ee:858) at mapIntoWithKeyPrefixInternal (react.development.js?99ee:934) at Object.mapChildren [as map] (react.development.js?99ee:956) at Accordion.preExpandedItems (accordion.js?96e3:68) at new Accordion (accordion.js?96e3:40) at constructClassInstance (react-dom.development.js?cada:9760)

The example of my code:

const isCompany = false;

<Accordion>
  <AccordionItem>
    <AccordionItemTitle className={styles.item}>
      <div className={styles.accordionArrow} role="presentation" />
      <h3 className={styles.itemHeader}>
        Accordion Header 1
      </h3>
    </AccordionItemTitle>
    <AccordionItemBody>
      <p>
        Accordion Body Content 1
      </p>
    </AccordionItemBody>
  </AccordionItem>
  
  {isCompany && (<AccordionItem>
    <AccordionItemTitle className={styles.item}>
      <div className={styles.accordionArrow} role="presentation" />
      <h3 className={styles.itemHeader}>
        Accordion Header 2
      </h3>
    </AccordionItemTitle>
    <AccordionItemBody>
      <p>
        Accordion Body Content 2
      </p>
    </AccordionItemBody>
  </AccordionItem>)}
</Accordion>

Could you please help me to resolve this problem?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ryami333commented, Feb 15, 2018

I sort of understand why this might happen given our current codebase, because the accordion Accordion component does some traversal of its ‘children’ and all of its children must be AccordionItem components. However, in this instance ^ there is a child where child === false (because {isCompany & foo} === false). Make sense?

A workaround would be to hide the AccordionItem with some additional className, rather than conditionally rendering it. We’re currently working a big new release which should resolve this undesired behaviour, so hold tight 😃

0reactions
ryami333commented, Feb 21, 2018

@volkova-annie this should be solved in v2.0.0 😀

Let us know how you get on with the upgrade!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'props' of null
I faced the same issue while using class className extends React.Component instead of createClass() . Create a variable in constructor to fix ...
Read more >
[bug] × TypeError: Cannot read property 'props' of null #197
Describe the bug TypeError: Cannot read property 'props' of null To Reproduce Steps to reproduce the behavior: This issue is intermittent ...
Read more >
How to fix Uncaught TypeError: Cannot read property 'props ...
In this post we will be discussing about how to fix "Uncaught TypeError: Cannot read property 'props' of null" in React.js.
Read more >
Cannot read property `property` of null in 'react-test-renderer ...
Recently, I ran into some problems while attempting to snapshot test my React code. TypeError: Cannot read property 'focus' of null.
Read more >
Uncaught TypeError: Cannot read property 'props' of null
Best Solution · 1. Manually bind this in class constructor · 2. Use ES7 Property initializers with arrow function · 3. Bind this...
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