I import outline and solid icon
import { HeartIcon } from "@heroicons/react/24/outline";
import { HeartIcon } from "@heroicons/react/24/solid";
const [isClick, setIsClick] = useState(false);
<HeartIcon onClick={()=>setIsClick(true)} >
{
isClick &&
<HeartIcon onClick=(()=>setIsClick(false))
}
How to import and how to use in React js
I have error one icon import outline and solid.
I want to toggle if outline heart is click, show solid heart icon.
2
Answers
You can use it as so:
If you need more info on this; let me know
First of all, please check the package version you’ve installed. Older versions would work fine without specifying the width when importing, and just returning the component with the desired width:
Then, you need to use an alias for at least one of them, so you don’t have duplicate identifiers.
For the toggle functionality, if you want to change from outlined to solid, you can simply set a boolean state to change the component that will render once it’s clicked.
If you want a toggle function, then you can do this: