Answer the question
In order to leave comments, you need to log in
What is the best way to implement card editing?
In my application there are cards of the form "first name - last name - phone number - address", the data in them can be edited.
Now editing is done like this:
<StyledMain>
<ElemInput
templateEdit={rest.action}
value={name}
cath={"name"}
/>
<ElemInput
templateEdit={rest.action}
value={surname}
cath={"surname"}
/>
<ElemInput
templateEdit={rest.action}
value={phone}
cath={"phone"}
/>
<ElemInput
templateEdit={rest.action}
value={address}
cath={"address"}
/>
</StyledMain>
class ElemInput extends React.Component {
returnValue = e => {
this.props.templateEdit(e, this.props.cath);
};
render() {
return (
<StyledInput
onChange={this.returnValue}
defaultValue={this.props.value}
/>
);
}
}
Answer the question
In order to leave comments, you need to log in
ElemInput is a useless wrapper with an interface that only you can understand, complicating the code.
Try to never write like that. If you are describing an interface, use traditional component property names (name, onChange etc).
See the official documentation for a good example of how to work with forms.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question