The reason for the query is because I am having trouble displaying the image that is loaded in the tag:
With the input event, the handleChange function is executed, in it it is confirmed that the event is the one corresponding to photo number 1, hence the if (fieldName == "photo1"). But the image is never displayed. Indeed in photo1, I get the name of the image and its shape.
How is it possible to show the image? o What am I doing wrong?
const SetItem = () =>{
const [foto1,setFoto1]=useState<string>("-");
const handleChange = (fieldName: string) => (e:any) => {
if(fieldName=="foto1"){
setFoto1(e.currentTarget.files[0].name);
let img=document.getElementById("imagen1");
(img! as HTMLImageElement).src=foto1!;
}
};
return(
<input id="inputFile1" type="file" accept="image/*" onChange={ handleChange("foto1")} />
<img id="imagen1" src={foto1} alt="your image" />
);
}