'FIlter state and update React Typescript

I wanted to filter and update the state

    const [files, setFiles] = useState<[]>([]);

    ..... 
    setFiles(acceptedFiles);
    .....
  
    const handleRemoveSelected = (imageName: string) => {
    const update = files.filter((f: any) => f.name !== imageName);
    
    setFiles(update)(Error is here)
  
[![Error on setFile(update)][1]][1]};

Error Argument of type 'never[]' is not assignable to parameter of type 'SetStateAction<[]>'. Type 'never[]' is not assignable to type '(prevState: []) => []'. Type 'never[]' provides no match for the signature '(prevState: []): []'.ts(2345

error on setFile(update)



Solution 1:[1]

It's not necessary to specify the type in your useState, TS will infer that your useState is an array type only doing useState([])

Cahnge this:

const [files, setFiles] = useState<[]>([]);

To this:

const [files, setFiles] = useState([]);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Braulio Monroy