cannot pass props to child component
See original GitHub issueHi, I’m trying to implement your mobx-react-form package by myself but I have following issue. I would like to pass props for example form={form.$(‘product’)} defined in NewProductForm.jsx into the component Input defined in Input.jsx.
I checked what I get when I write console.log(props.form) in Input component and it tells me that form.$(‘product’) is empty array and is rendered just this tag <input type="text" />
. Probably I’m not passing props correctly but I dont how I can do it in another way.
fields definition in FormFieldConst.jsx
export default {
fields: {
product: {
name: 'productname',
label: 'productname',
placeholder: 'write product name',
rules: 'required|string|between:5,65',
}
....
}
ValidationForm.jsx
const plugins = { dvr: validatorjs };
class ValidateForm extends MobxReactForm {
onSuccess(form) {
console.log(form.values());
}
onError(form) {
console.log(form.errors());
}
}
const validateform = new ValidateForm({ fields, plugins });
export default { validateform };
NewProductForm.jsx
import form from '../components/ValidationForm';
const NewProductForm = () => (
<form className={styles.newform} onSubmit={form.onSubmit}>
<Input className="form-input" type="text" form={form.$('product')} />
<Input className="form-input" type="text" form={form.$('inventory')} />
<Input className="form-input" type="text" form={form.$('type')} />
<Input className="form-input" type="text" form={form.$('vendor')} />
<Button classBtnName="form-button" BtnText="Send Form" />
</form>
);
export default observer(NewProductForm);
Input.jsx
const Input = props => (
<div className={props.className}>
<label htmlFor={props.form.label} >
</label>
<input type={props.type} name={props.form.name} value={props.form.name} placeholder={props.form.placeholder} onChange={props.form.sync} />
</div>
);
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Why can I not pass props to child component React?
I currently have code for the date to update and pass to a date component, but now working on a stopwatch and having...
Read more >Passing Props to a Component - React Docs
React components use props to communicate with each other. Every parent component can pass some information to its child components by giving them...
Read more >How to Use Props to Pass Data to Child Components in React.js
The last step is to access the props in the child component. In function components, we access the props through the first function...
Read more >How to pass props to a component in React
We cannot pass props from a child component to a parent component. Props always move from top to bottom in the component hierarchy....
Read more >How to use Props in React - Robin Wieruch
As said, there is no way passing props from a child to a parent component. But you can always pass functions from parent...
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
Now you can use
placeholder
. The docs is updated too.About extending the forms and fields, I will create a more detailed guide for it.