khteh
khteh

Reputation: 3956

ReactJS props.onchange destructuring

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>

Upvotes: 0

Views: 192

Answers (2)

Chirag valecha
Chirag valecha

Reputation: 1

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

const { ...rest,onChange } = props;

Upvotes: -2

Jonatan Kruszewski
Jonatan Kruszewski

Reputation: 1306

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>

Upvotes: 1

Related Questions