2

I want to why my code is not working and causing me this error Argument of type 'unknown' is not assignable to parameter of type 'SetStateAction<string>'. Type 'unknown' is not assignable to type '(prevState: string) => string'.ts(2345).

This error is from this code setBaseImage(base64); of this function:

 const uploadImage = async (e: any) => { const file = e.target.files[0]; const base64 = await convertBase64(file); setBaseImage(base64); }; 

Current code:

 const [baseImage, setBaseImage] = useState(""); const convertBase64 = (file: any) => { return new Promise((resolve, reject) => { const fileReader = new FileReader(); fileReader.readAsDataURL(file); fileReader.onload = () => { resolve(fileReader.result); }; fileReader.onerror = (error) => { reject(error); }; }); }; 

I just follow this tutorial source of the code

1 Answer 1

4

Already solve the issue by updating this line of code:

setBaseImage(String(base64)); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.