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.

Null reference scenario with unkeyed children

See original GitHub issue

I found a problem with using ref on unkeyed children. You can observe the problem here: https://jsfiddle.net/rsm2dxb7/1/ Open the console and click Toggle. You’ll see that the final dom reference being passed is null, which is wrong because the referenced div is still there.

In the example, the first child is conditionally rendered and the second child is using a ref. On click, the state changes and the first child is unmounted. The ref callback is called two times in wrong order, so the final reference value is null.

{ header && <div className="header">Header</div> }
<div ref={c=>{
  console.log(c);
}}>
  Content
</div>

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
yaodingydcommented, Mar 16, 2018

Essentially duplicate of #857. Although this was raised earlier, looks like the main discussion is in #857. @Rendalf For now unkeyed diff has this issue which cannot be resolved. You can use keyed children if possible.

0reactions
marvinhagemeistercommented, Apr 12, 2019

Related to #1440

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# Children and SubChildren Null Reference Exception
Hi everyone, in one of my scripts I'm getting a null reference exception and I'm trying to figure out why. The console says...
Read more >
Unable to get property 'children' of undefined or null reference
I am frequently getting this error as well. This almost always happens as I am saving a new task that was created from...
Read more >
Ultimate Guide to JSON Parsing with Swift - Ben Scheirman
This is a guide that will take you through almost any scenario you might encounter when translating JSON representations to your Swift types....
Read more >
All labs | Web Security Academy - PortSwigger
Mystery lab challenge Try solving a random lab with the title and description hidden. As you'll have no prior knowledge of the type...
Read more >
PacketCable™ Security Specification PKT-SP-SEC-I06-021018
architecture as a point of reference for the remainder of the document. ... [1] B. Schneier, “Applied Cryptography,” John Wiley & Sons Inc,...
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