如何获得 selected 值 onChange of react redux-form react-select

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

我正在使用带有 react-select 的 redux-forms 文件。更改值后,onChange 函数会显示该值。我想检查值并​​为特定值打开一个对话框让用户确认 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}
    })}
  />
)

您可以使用 formValues - 它是一个 redux 表单选择器,returns 您可以使用表单中的所有数据。 https://redux-form.com/7.2.3/docs/api/formvalues.md/

但是您应该知道,一旦您将 formValues 选择器应用于组件,它就会对每个字段中的每个更改做出反应(不仅仅是您需要查看的字段)。这会使该组件的性能恶化。