79539600

Date: 2025-03-27 17:22:21
Score: 1
Natty:
Report link

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"
    }
  
}
Reasons:
  • RegEx Blacklisted phrase (1): i want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Anshuman