javascriptreactjsreact-redux-form

React: The `value` prop supplied to <select> must be a scalar value if `multiple` is false


I am getting this warning:

Warning: The value prop supplied to must be a scalar value if multiple is false. Check the render method of Control.

I am using the React Redux Form https://davidkpiano.github.io/react-redux-form/docs/api/Control.html#prop-defaultValue.

The data is coming in as an array of objects to display inside of the select options element. I don't want to turn the control into a multiple since we only want the user to select one value.

How would I go about solving this warning?


Solution

  • if you use an array in your state it will get that error if you are not doing multiple searches

    if it is a simple search use single quotes ''

    in useState('')

    const [categoria, setCategoria] = useState('')
    
    <select
            onChange={e => setCategoria(e.target.value)}
            value={categoria}
           >
    </select>