Reactjs : Getting a input value from many inputs

Viewed 88

Im trying to get some input value from a library(https://www.npmjs.com/package/react-auth-code-input) , but im getting an error TypeError: Cannot read properties of undefined (reading 'value')

code :

  {...}
const Login = ({loginUser}) =>{
  const history = useHistory();
  const [showPopup, setShowPopup] = useState(false);
  const [Token,setToken] =useState(0);


  return (
    <div>
      <StyledFormArea>
        <TextLink to="/home">
           {...}
 <AuthCode
                          characters={6}
                          onChange= {e => setToken(e.target.value)}
                          containerClassName="Input"
                          inputClassName="input"
                        />
{...}

someone knows an function that gets more than one input value ?

1 Answers

The onChange method from the library definition tells you that the return value is the a string (assuming it’s the input string value), no the event. So instead of e.target.value it would just be e (I would rename this :) )

For reference here is the definition of the onChange method implementation from the library (found here)

Callback function called every time an input value changes

So the onChange Will give you the text value of the input.

Related