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

Creating new icons triggers 'unique "key" prop' error #2153

Closed
6 tasks done
mathis-girault opened this issue May 14, 2024 · 3 comments
Closed
6 tasks done

Creating new icons triggers 'unique "key" prop' error #2153

mathis-girault opened this issue May 14, 2024 · 3 comments
Labels
🐛 bug Something isn't working

Comments

@mathis-girault
Copy link

mathis-girault commented May 14, 2024

Package

  • lucide-react

Version

0.378.0

Can you reproduce this in the latest version?

  • Yes

Browser

  • Firefox
  • Edge

Operating system

  • Windows

Description

When creating a custom Icon component, with createLucideIcon function, and then using the new icon somewhere in a list, the following error appears on the console:

Warning: Each child in a list should have a unique "key" prop.

This bug occured within a 'big' project so I tried to trigger it on a just created project: same issue.
Besides creating a react app and installing lucide-react, I simply wrote this code:

import './App.css';
import { createLucideIcon } from 'lucide-react';

const MyIconNode = [
  ['path', { d: 'M8 2v4' }],
]

const MyIcon = createLucideIcon('MyIcon', MyIconNode)

function App() {
  return (
    <div className="App">
      {[1, 2, 3].map((number) => (
        <div key={number}>
          <MyIcon />
        </div>
      ))}
    </div>
  );
}

export default App;

I am not sure what is causing this and hope I didn't miss an obvious error.

Steps to reproduce

  1. Create a react app (tried both js and ts) and install lucide-react
  2. Create a new icon with createLucideIcon (with a name a an icon node)
  3. Render the newly created icon inside a map method for exemple

For step 3, created icon cannot support a key prop, and putting the icon inside a div that has a key doesn't solve the issue.

Checklist

  • I have searched if someone has submitted a similar issue before and there weren't any. (Please make sure to also search closed issues, as this issue might already have been resolved.)
@mathis-girault mathis-girault added the 🐛 bug Something isn't working label May 14, 2024
@ericfennis
Copy link
Member

You can easily fix this by adding a key prop in the iconNode:

const MyIconNode = [
  ['path', { d: 'M8 2v4', key: 'path1' }],
]

@mathis-girault
Copy link
Author

Awesome, this works perfectly.

I'll close the issue as this solves it entirely (it could maybe be added to the documentation, I was not able to find this information on my own).

@jguddas
Copy link
Member

jguddas commented May 22, 2024

Awesome, this works perfectly.

I'll close the issue as this solves it entirely (it could maybe be added to the documentation, I was not able to find this information on my own).

Be the change you want to see in the world 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants