Search code examples
reactjsredux-formreact-select

How to get selected value onChange of react redux-form react-select


I'm using redux-forms fileds with a react-select. After changing the value the onChange function does show the value. I want to check the value and for specific values open a dialog box to let the user confirm the selection.

import SelectBox from "react-select"

const checkValue= (e) => {
  console.log(e.target.value)
}

const Select= ({...props }) => (
  <Field
    {...props}
    component={SelectBox}
    onChange={e => checkValue(e)}
    items={myItems}
    })}
  />
)

Solution

  • You can user formValues - it is a redux-form selector which returns you all the data from the form. https://redux-form.com/7.2.3/docs/api/formvalues.md/

    But you should know that once you apply formValues selector to a component it will react to every change in every field (not only the ones you need to look at). This can worsen the performance of this component.