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

Menu Items have not got unique keys #26

Open
Prince-Jonathan opened this issue Jul 7, 2020 · 1 comment
Open

Menu Items have not got unique keys #26

Prince-Jonathan opened this issue Jul 7, 2020 · 1 comment

Comments

@Prince-Jonathan
Copy link

Prince-Jonathan commented Jul 7, 2020

In my console, I keep getting this warning:

Warning: Encountered two children with the same key, Others. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version

I believe this feature enables react to efficiently update the DOM. My only concern is if something is being done about it. Or better asked: what can I do to resolve this?

@Prince-Jonathan Prince-Jonathan changed the title Many Items have not got unique keys Menu Items have not got unique keys Jul 7, 2020
@mmeesit
Copy link

mmeesit commented Jan 27, 2021

If you look into the project the renderItem function in index.js is incorrect: since the key and value are identical values, it will always show the errors. I modified the code like this:

      <div
        key={`${item.value}_${level}`}
        className={`item item-level-${level} ${item.active ? 'active' : ''}`}>

and for the render children part like this:

        <div key={`${item.value}-children-level-${level}`} className={`children ${item.active ? 'active' : 'inactive'}`}>
          {item.children && item.children.map((child) =>
            this.renderItem(child, level + 1)
          )}
        </div>

and divider:

        <div key={`${item.value}-divider_${level}`} className={`divider divider-level-${level}`}>
          { item.label }
        </div>

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

No branches or pull requests

2 participants