question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to access props in initialValues of redux form

See original GitHub issue

@erikras @kvedananda

const selector = formValueSelector('athlete_profile_form');

AthleteProfileForm = reduxForm({
  form: 'athlete_profile_form',
  initialValues: {athlete_last_name: 'testadassa'}
})(AthleteProfileForm);

AthleteProfileForm = connect((state, ownProps) => ({
  FirstName: selector(state, 'athlete_first_name'),
  LastName: selector(state, 'athlete_last_name'),
  Country: selector(state, 'country'),
  DOB: selector(state, 'dob'),
  Gender: selector(state, 'gender'),
  Address: selector(state, 'address'),
  TimeZone: selector(state, 'timezone'),
  MobileNumber: selector(state, 'mobile'),
  Height: selector(state, 'height'),
  Weight: selector(state, 'weight'),
  Bio: selector(state, 'bio'),
  HighSchoolName: selector(state, 'highschool'),
  HighSchoolYear: selector(state, 'highschool_year'),
  HighSchoolUniversity: selector(state, 'highschool_university'),
  HighSchoolProgramLength: selector(state, 'highschool_length'),
  GraduationName: selector(state, 'graduation'),
  GraduationYear: selector(state, 'graduation_year'),
  GraduationUniversity: selector(state, 'graduation_university'),
  GraduationProgramLength: selector(state, 'graduation_length'),
  SportPlayed: selector(state, 'sports_played'),
  SportYear: selector(state, 'practice_year')
}))(AthleteProfileForm);

I have this component structure but I cannot access props

When I use the below format of using initialValues

AthleteProfileForm = reduxForm({
  form: 'athlete_profile_form'
})(AthleteProfileForm);

AthleteProfileForm = connect((state, ownProps) => ({
  FirstName: selector(state, 'athlete_first_name'),
  LastName: selector(state, 'athlete_last_name'),
  Country: selector(state, 'country'),
  DOB: selector(state, 'dob'),
  Gender: selector(state, 'gender'),
  Address: selector(state, 'address'),
  TimeZone: selector(state, 'timezone'),
  MobileNumber: selector(state, 'mobile'),
  Height: selector(state, 'height'),
  Weight: selector(state, 'weight'),
  Bio: selector(state, 'bio'),
  HighSchoolName: selector(state, 'highschool'),
  HighSchoolYear: selector(state, 'highschool_year'),
  HighSchoolUniversity: selector(state, 'highschool_university'),
  HighSchoolProgramLength: selector(state, 'highschool_length'),
  GraduationName: selector(state, 'graduation'),
  GraduationYear: selector(state, 'graduation_year'),
  GraduationUniversity: selector(state, 'graduation_university'),
  GraduationProgramLength: selector(state, 'graduation_length'),
  SportPlayed: selector(state, 'sports_played'),
  SportYear: selector(state, 'practice_year'),
  initialValues: {athlete_last_name:  ownProps.userData.firstName ? ownProps.userData.firstName :  'testa'}
}))(AthleteProfileForm);

In this case my initial values api doesn’t work at all, because i don’t even see the harcode data string ‘test’ being displayed

This is a material-ui-redux-form library I’m using

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
vaibhav-systangocommented, May 31, 2017

@MathieuDoyon

Using initialize function & setting enableReinitialize param to true in form works great

class AthleteProfileForm extends Component { static propTypes = { initialize: React.PropTypes.func.isRequired }

componentDidMount() { this.props.initialize(this.props.userData) } render() { return (

); } } AthleteProfileForm = reduxForm({ form: ‘athlete_profile_form’, enableReinitialize: true, })(AthleteProfileForm);

AthleteProfileForm = connect((state, ownProps) => ({ FirstName: selector(state, ‘athlete_first_name’) }))(AthleteProfileForm);

export default AthleteProfileForm;

2reactions
MathieuDoyoncommented, May 31, 2017

@vaibhav-systango using enableReinitialize: true work for me

UsersShowForm = reduxForm({
  form: 'UsersShowForm',
  enableReinitialize: true
})(UsersShowForm)

ref: https://stackoverflow.com/a/38906956

Read more comments on GitHub >

github_iconTop Results From Across the Web

can i get initialValues passed from props? · Issue #916 - GitHub
The initialValues prop is "consumed" by the redux-form HOC (not passed through). However, you are free to pass the same values via any...
Read more >
Initializing From State - Redux Form
Values provided to the initialValues prop or reduxForm() config parameter will be loaded into the form state and treated thereafter as "pristine".
Read more >
Redux-Form initial values from - reactjs - Stack Overflow
initialize() is a prop provided by reduxForm, that can be used to fill up the form values. change() is another prop provided by...
Read more >
How To Add Initial Values into Your Redux Form - Medium
To do this, in your mapStateToProps() function, create a key called initialValues that is set to an object that contains the keys and...
Read more >
React JS Redux Form with Initial value, Validations and Props ...
To use Redux form you need to add redux-form reducer with our store as shown in below code. Create src/redux/ConfigureStore.js as follow.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found