Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix React duplicate key warning #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eerohele
Copy link

@eerohele eerohele commented Jun 8, 2018

If a notification is rendered more than once simultaneously, React throws a warning like this:

react-dom.inc.js:18238 Warning: flattenChildren(...): Encountered two children with the same key, `...`. Child keys must be unique; when two children share a key, only the first child will be used.

Using the index of the item instead of the options map as the key fixes the issue. It should be safe here since a notification component is never re-rendered.

Further testing demonstrated the statement above false. Using the index as the key caused the notifications to get messed up in situations where multiple different notifications were rendered simultaneously.

Generating a UUID for each notification seems to work better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant