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

[BUG] Mapping key has multiple children #128

Closed
ballyalley-o opened this issue Apr 14, 2024 · 0 comments · Fixed by #135
Closed

[BUG] Mapping key has multiple children #128

ballyalley-o opened this issue Apr 14, 2024 · 0 comments · Fixed by #135
Labels
bug Something isn't working solved

Comments

@ballyalley-o
Copy link
Owner

ballyalley-o commented Apr 14, 2024

Describe the bug

Image

It seems like you're encountering a warning related to React, specifically about non-unique keys within components. In React, when rendering a list of elements, each element should have a unique "key" prop assigned to it. This allows React to efficiently update and manage the list.

The warning you're seeing indicates that you have two children within a component that share the same key, which can lead to unexpected behavior such as duplicated or omitted elements.

To resolve this warning, ensure that each child element within the component has a unique key prop assigned to it. You can use unique identifiers such as database IDs or index values if no other unique identifier is available. This ensures React can properly reconcile and update the list elements.

potential fix:

function MyComponent({ items }) {
  return (
    <ul>
      {items.map((item, index) => (
        <li key={item.id}>{item.name}</li>
      ))}
    </ul>
  );
}

In this example, assuming each item in the items array has a unique id, we're using item.id as the key prop to ensure uniqueness. Make sure to replace item.id with the actual unique identifier in your code.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'Dashboard'
  2. Open devtools
  3. Refresh
  4. See error

Important

Error is comming from AnimateProsence from framer-motion, due to the children it is wrapping, solution is to map its children.

Solution

    <AnimatePresence>
          {React.Children.map(children, (child, index) => (
            <m.div key={index}>{child}</m.div>
          ))}
        </AnimatePresence>

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@ballyalley-o ballyalley-o added the bug Something isn't working label Apr 14, 2024
@ballyalley-o ballyalley-o moved this to 🗂️ Backlog in The Code Coach Projct™ Apr 14, 2024
@ballyalley-o ballyalley-o moved this from 🗂️ Backlog to Sprint 2 in The Code Coach Projct™ Apr 14, 2024
@ballyalley-o ballyalley-o moved this from Sprint 2 to In Progress in The Code Coach Projct™ Apr 15, 2024
ballyalley-o added a commit that referenced this issue Apr 15, 2024
…r use-snack.tsx to import React and update AnimatePresence usage):
@ballyalley-o ballyalley-o linked a pull request Apr 15, 2024 that will close this issue
ballyalley-o added a commit that referenced this issue Apr 15, 2024
* Refactor AccountPopover component to use index as key in MenuItem

* 🐞 fix([BUG] Mapping key has multiple children #128: Solution: Refactor use-snack.tsx to import React and update AnimatePresence usage):

* destructure Children from react instead #136: Update import statement in use-snack.tsx
@ballyalley-o ballyalley-o moved this from In Progress to Done in The Code Coach Projct™ Apr 15, 2024
@ballyalley-o ballyalley-o moved this from Done to in QA in The Code Coach Projct™ Apr 15, 2024
@ballyalley-o ballyalley-o moved this from in QA to Done in The Code Coach Projct™ Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working solved
Projects
Status: Done
1 participant