2

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
@ndvictor14 Like this ? onChange= {e => setToken(e)} then it will be stored in my state TOken ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.