i have done this using ref <img src="/eye.svg" width={20} /
//so i want to change this img src
1)add a function to it using on click and a ref
<img src="/eye.svg" width={20} ref={ref} onClick={Function_name}/
2)Here's the function code we used src.includes to check if string exist or you can say the previous path exist i have made this fuction to toggle img on click if you just want to change the src for once you should do then this.
a)without toggle const ref= useRef()
const Function_name = () => {
ref.current.src = "public/hidden.svg"
}
b) with toggle
const ref= useRef()
const Function_name = () => {
if(ref.current.src.includes("public/eye.svg")){
ref.current.src = "public/hidden.svg"
}
else{
ref.current.src = "public/eye.svg"
}
}