Search code examples
javascriptreactjsreact-final-form

Dropdown `value` must be an array when `multiple` is set. Received type: `[object String]`


I am getting this error

Dropdown value must be an array when multiple is set. Received type: [object String].

here is my code https://codesandbox.io/s/cool-torvalds-lhe9d

I already provide a default value blank array.

<Dropdown
        {...restProps}
        value={value || []}
        {...props.input}

Solution

  • You're getting the error because of {...props.input} which has a property value

    name: "zones"
    value: "" // <--- this is [object String]
    type: undefined
    onBlur: function () {}
    onChange: function () {}
    onFocus: function () {}
    

    Which is overwriting the value attribute you set right before it

     <Dropdown
          {...restProps}
          value={value || []}
          {...props.input} // <--- the value here is overwriting the value attribute before it.
          clearable
          fluid
          multiple
    

    So, to fix this, just move the value attribute one step down :

    <Dropdown
          {...restProps}
          {...props.input}
          value={value || []}
          clearable
          fluid
          multiple