New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can i get initialValues passed from props? #916
Comments
The Basically, you make a function such as:
This function needs to return a plain object. This object gets merged into your components props. Well, if you return an object with key
Notice that Hope that helps! |
I might not understand the question but can't you just do
? |
I, too, am not 100% sure what you mean, but I'm going to guess. The <MyForm
initialValues={myFormData} // <--- will be used and not passed through
initialValuesToPassThru={myFormData}/> // <--- will be ignored and passed through |
thank you for your answers. the MyForm component sits under a route, and renders:
should i pass the props from outside the component? p.s. @juanpaco 's answer works great, but i'd rather @erikras ' approach |
<form initialValues={{ Country: "US" }} onSubmit={handleSubmit}>
// ^^ No, that's the React.DOM.form component. You need to pass it to your
// decorated component, the result of using reduxForm() on the component
// that this render() method is in. |
yes, it did help. thank you guys |
@erikras is this still actual? import React from 'react';
import { Field, reduxForm } from 'redux-form';
const ModifyItemBody = ({ handleSubmit, body }) => (
<form onSubmit={handleSubmit} initialValues={{newbody: body}}>
<Field name="newbody" component="input" type="text"/>
<button type="submit">Submit</button>
</form>
);
export default reduxForm({
form: 'modifyItem', // a unique name for this form
enableReinitialize: true
})(ModifyItemBody);
|
Ah ok, I needed to pass the actual prop when the Component was called: <ModifyItemBody body={body} onSubmit={handleSubmit} editmode={!editmode} id={id} initialValues={{newbody: body}} /> @erikras do you mind adding this way of passing initialValues to the documentation/FAQ? I didn't see it anywhere and it seems that the only way possible (still by digging the issue tracker) is the use the config/mapStateToProps .. (looked for that for 3-4h :( ) |
@gkatsanos Perhaps the IMPORTANT: All of these configuration options may be passed into reduxForm() at "design time" or passed in as props to your component at runtime. could be in a bigger font? That line does cover what you're talking about, right? I'm open to suggestions of how to make the docs clearer. What would you write, and where? |
Hey Erik, you're right actually in both things:) it's there but yes the fonts are overall rather problematic.. : |
@thomasmery Thanks, your solution worked! |
Late answer to #916 (comment): it's open source. Just look at the other available branches here :) cc @gkatsanos |
The mapStateToProps doesn't seem to work. |
Nevermind. I just had to reverse the order of connect and reduxForm like in this answer https://stackoverflow.com/a/48855532/5605365 |
i have this redux-form code:
i want to pass the initialValues from MyForm.props.initialValues.
how can i access my components props?
The text was updated successfully, but these errors were encountered: