viclafouch / mui-file-input

A file input designed for the React library MUI
https://viclafouch.github.io/mui-file-input/
MIT License
77 stars 17 forks source link

[DOC] - Typescript example is missing File[] #23

Closed marcusflat closed 1 year ago

marcusflat commented 1 year ago

On typescript section, the type of useState and handleChange newValue param is missing File[];

import React from 'react'
import { MuiFileInput } from 'mui-file-input'

const MyComponent = () => {
  const [value, setValue] = React.useState<File | null>(null)

  const handleChange = (newValue: File | null) => {
    setValue(newValue)
  }

  return (
    <MuiFileInput
      value={value}
      onChange={handleChange}
      hideSizeText
    />
  )
}

I got the error: Type '(newValue: File | null) => void' is not assignable to type '(value: File | File[] | null) => void'.

The correct type is: File | File[] | null

Doc Page

viclafouch commented 1 year ago

Issue has been fixed in v2.0.4, the typing was wrong in the code, not in the documentation.

onChange

Gets called once the user updates the file value.

Example:


const handleChange = (value) => {}

<MuiFileInput onChange={handleChange} />

Thanks for the catch @marcusflat