Answer the question
In order to leave comments, you need to log in
How to correctly pass a parameter to a function?
Hello everyone. I use React and TypeScript
Please tell me, there are two inputs, value which are stored in the state.
There is a function in the class.
changeValue = (e: any, nameInput: string):void => {
const value = e.target.value;
this.setState({ [nameInput]: value })
}
<Input
placeholder="Name"
value={modalName}
onChange={(e) => { this.changeValue(e, modalName) }}
/>
<Input
placeholder="Description"
value={modalDescr}
onChange={(e) => { this.changeValue(e, modalDescr) }}
/>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question