ReactJS props.onchange destructuring

Kok How Teh

How to fix the following props destructure for ReactJS without having to turn off "react/destructuring-assignment"? Thanks.

const AutocompleteField = (props) => {
  const { ...rest } = props
  const { control, handleSubmit, errors, setError } = useFormContext()

  return (
    <Root>
      <Autocomplete
        multiple
        limitTags={1}
        options={CATEGORIES}
        getOptionLabel={(option) => (typeof option === 'string' ? option : option.title)}
        onChange={(event, value) => props.onChange(value)}
<snip>
Jonatan Kruszewski

If it is raising at the props.onChange(value). If so, you could try something like:

const AutocompleteField = ({onChange, ...rest}) => {
  const { control, handleSubmit, errors, setError } = useFormContext()

  return (
    <Root>
      <Autocomplete
        multiple
        limitTags={1}
        options={CATEGORIES}
        getOptionLabel={(option) => (typeof option === 'string' ? option : option.title)}
        onChange={(event, value) => onChange(value)}
        {...rest}
<snip>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Destructuring props in ReactJS

Reactjs ; destructuring props assignment with ESLint rules

Reactjs add onChange to props.children dynamically

ReactJS Unit Testing - TypeError: this.props.onChange is not a function

ReactJS: Select with default value from props without onChange event?

component props destructuring error

Destructuring props dynamically?

destructuring props with the rest properties

Destructuring state/props in React

Destructuring this.props into Component

Initialize Destructuring props if null

React - TypeScript destructuring of props

Different ways of destructuring props in react

React: Props destructuring and memory usage

Must use destructuring props assignment

Typescript + React: Use props AND (!) destructuring

Props in ReactJS

ReactJS: State does not update upon onChange when initial state is from props

reactjs - Why have form value state updated through both parent props and component onChange?

unable to add onChange props in react-select's multi selection in ReactJS Typescript?

React pass props to onChange

Must use destructuring props assignment (react/destructuring-assignment)

Destructuring ImmutableJS Map for React Component Props

Spreading props on a component and destructuring inside a components with typescript

Must use destructuring props assignment error in constructor

How i can destructuring {this.props.children}?

React props destructuring when passing to component

Must use destructuring props assignment in className

Destructuring props in the function parameters using TypeScript