redux-form : How to display form values on another component

有些话、适合烂在心里 提交于 2019-12-01 04:44:47

Try using

List = connect(
  state => ({
    values: getFormValues(state.form.formName)
  })
)(List)

instead. At least that's how it worked in v5, although there the method was called getValues and not getFormValues.

Edit: After a quick look at the docs it seems in v6 you'll have to use a formValueSelector: http://redux-form.com/6.0.0-rc.3/examples/selectingFormValues/

formValueSelector() is not necessary.

You also can directly access it as a property.

List = connect(
  state => ({
    formValues: {
       id: state.form.formName.values.id
    }
  })
)(List)

Same as

List = connect(
  state => ({
    formValues: {
       id: formValueSelector('formName')(state, 'id')
    }
  })
)(List)
Ido

I had the same problem. Apparently, 'values' is a saved name in redux-form. Using Iurii Budnikov advice I managed to solve the problem - just change the the variable name from 'values' to something else in your connect call:

List = connect(
  state => ({
    formValues: getFormValues(state.form.formName)
  })
)(List)

Starting from redux-form 6.0.0 (and still the same in 7.0.0), you can use the function formValueSelector() to select values from any redux form you have in your application: http://redux-form.com/7.0.0/docs/api/FormValueSelector.md/

import { connect } from 'react-redux';
import { formValueSelector } from 'redux-form';

const selector = formValueSelector('formName');

List = connect(
  state => ({
    name: selector(state, 'name')
  })
)(List)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!