#How do i fix this error, while using new FormData(), using use state hook

2 messages · Page 1 of 1 (latest)

worthy hornet
#
  const [title, setTitle] = useState("");
  const [summary, setSummary] = useState("");
  const [content, setContent] = useState("");
  // const [files, setFiles] = useState("");
  const [files, setFiles] = useState<FileList | null>();

  const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
    const data = new FormData();
    data.set("title", title);
    data.set("summary", summary);
    data.set("content", content);
    data.set('file', ~~files~~) //error on files

No overload matches this call.
Overload 1 of 3, '(name: string, value: string | Blob): void', gave the following error.
Argument of type 'FileList | null | undefined' is not assignable to parameter of type 'string | Blob'.
Type 'undefined' is not assignable to type 'string | Blob'.
Overload 2 of 3, '(name: string, value: string): void', gave the following error.
Argument of type 'FileList | null | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
Overload 3 of 3, '(name: string, blobValue: Blob, filename?: string | undefined): void', gave the following error.
Argument of type 'FileList | null | undefined' is not assignable to parameter of type 'Blob'.
Type 'undefined' is not assignable to type 'Blob'.ts(2769)

pallid valley
#

This does not appear to be related to Typescript itself.
FormData expects a single Blob there, and files is a FileList