The function "mostrarError" come from props and I put it into the function "handleImagenSeleccionada" but when it´s used in the "catch(error)", it´s displayed the next error: Uncaught (in promise) TypeError: mostrarError is not a function.
export default function LoadImage({ mostrarError }) {
const [imagenURL, setImagenURL] = useState('');//URL gotten from the backend when the image was loaded in the server
const [subiendoImagen, setSubiendoImagen] = useState(false);// For the loading
//------------------------ Functions ---------------------------------
async function handleImagenSeleccionada(evento) {
try {
setSubiendoImagen(true);
const file = evento.target.files[0];
const formData = new FormData();
formData.append('image', file);
const { data } = await Axios.post(baseURL + '/inside/postImage', formData, { headers: { "Content-type": "multipart/form-data" } });
setImagenURL(data.url);
setSubiendoImagen(false);
} catch (error) {
setSubiendoImagen(false);
console.log(mostrarError);
mostrarError(error.response.data.message);
}
}
return (
//Form in JSX
);
}
I used console.log to show "mostrarError" and the cosoles shows me that "mostrarError" is a function. enter image description here