React for Designers and PMs
Using icons
How to use icons in your React code
LLM Written
Human Written
Output
20
Click on the buttons
File Structure
├── src
` `├── App.tsx `← we are here`
` `├── index.css
` `└── main.tsxDistraction free code
const [cartCount, setCartCount] = 20;
<button onClick="setCartCount(cartCount - 1)">
<Minus />
</button>
{ cartCount }
<button onClick="setCartCount(cartCount + 1)">
<Plus />
</button>Code
'use client';
import { useState } from 'react';
import { Plus, Minus } from 'lucide-react';
export default function Home() {
const [cartCount, setCartCount] = useState(20);
return (
<>
<button
className='w-16 bg-blue-500 text-white px-4 py-2 rounded inline-flex justify-center'
onClick={() => setCartCount(cartCount - 1)}>
<Minus size={16} />
</button>
<span className='inline-block text-center w-16 bg-white text-blue-700 px-2 py-1 rounded-full'>{cartCount}</span>
<button
className='w-16 bg-blue-500 text-white px-4 py-2 rounded inline-flex justify-center'
onClick={() => setCartCount(cartCount + 1)}>
<Plus size={16} />
</button>
</>
);
}What's new?
- We imported `Plus` and `Minus` icons from the `lucide-react` library.
- We replaced the `-` and `+` text in the buttons with the corresponding icons.
- `<Minus size={16} />` is how to use the `Minus` icon as a React component. The same applies to any icon you want to use from the `lucide-react` library.
- Try adding other icons from the `lucide-react` library and see how they look!Layer visualization
Layers
Approximation of how this code would look in Figma's layer panel.
Home
cartCount"20"
RootFragment
DecrementButton
MinusIcon"size=16"
CartCountDisplay"{cartCount}"
IncrementButton
PlusIcon"size=16"
Select a layer to inspect