Home > Software engineering >  How to give the String value to the parameter in OnChange in React?
How to give the String value to the parameter in OnChange in React?

Time:08-29

I have a component that has an input tag called StandardInput.

At this time, when onChange is triggered, I want to execute the LsonChangefunc function, put a string value in the lstandtime1 state, and give a string value called Distinction as a parameter. So I want to run the condition according to the value of the distinction.

An argument for 'Distinction' was not provided.

How should I fix my code?

this is my code

const [lstandtime1, setLstandtime1] = useState('');

const LsonChangefunc = (e, Distinction) => {
  e.preventDefault();
  if (Distinction === "number1") {
    setLstandtime1(e.target.value) 
  }

}

return (
  <StandardInput
    value={lstandtime1}
    onChange={() => LsonChangefunc("number1")}
  />
)

CodePudding user response:

You have to pass two parameters in LsonChangefunc. In this case you need to pass event as first argument and 'number1' as second argument.

<StandardInput
  value={lstandtime1}
  onChange={(event) => LsonChangefunc(event, "number1")}
/>
  • Related