On React, I attempted making a feature to let user can see active feedback on screen by changing its icon when they click it.
How can I let it change to another icon (e.g. from Box to BoxChecked) once I click it?
note: I know this code line is the problem...(sob)
<img src={click} alt="icon" onClick={handleClick} />
App.jsx
import React, { useState } from 'react'
import './App.css'
import { GrCheckbox as Box } from 'react-icons/gr'
import { GrCheckboxSelected as BoxChecked } from 'react-icons/gr'
export default function App() {
const [icon, setIcon] = useState(false);
const [click, setClick] = useState(Box);
function handleClick() {
setIcon(!icon);
icon ? setClick(Box) : setClick(BoxChecked);
}
return (
<div className="App">
<img src={click} alt="icon" onClick={handleClick} />
<p>Clicked {click} times</p>
</div>
);
}