How to access props in initialValues of redux form
See original GitHub issueconst 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:
- Created 6 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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;
@vaibhav-systango using
enableReinitialize: true
work for meref: https://stackoverflow.com/a/38906956