0

I am writing a script where I have to change a variable value same as the input. This is my script. It should change whenever the input is changed -

    const handleUserInputChange = (e) => {
      MeetingIDi = e.target.name;
      fetchTrans()
      
    };

return <RightWrapper>
        <Header>
          <Button onClick={handleDelete}>Delete Transcription</Button>
          <Button onClick={signOut}>Sign out</Button>
          <input type="text" placeholder="Meeting ID" value={MeetingIDi} onChange={handleUserInputChange}/>
        </Header>

The value is not changing on input somehow

1
  • Store the variable in state - look up the useState hook Commented May 19, 2022 at 17:25

2 Answers 2

1
// Initialize MeetingIDi with a value of '' (use whatever you want)
const [MeetingIDi, setMeetingIDi] = useState('')

const handleUserInputChange = (e) =>
{
  setMeetingIDi(e.target.name);
  fetchTrans()
};

return <RightWrapper>
        <Header>
          <Button onClick={handleDelete}>Delete Transcription</Button>
          <Button onClick={signOut}>Sign out</Button>
          <input type="text" placeholder="Meeting ID" value={MeetingIDi} onChange={handleUserInputChange}/>
        </Header>

Using the state hook

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

2 Comments

I'm not able to input anything with the change now
What happens if you exchange e.target.name with e.target.value?
0

you can try to create a react useState hook to store the values in it and when the input is changing set the 'setValue' to the target value. Like the code below:

    const[value,setValue]= useState('');

return <RightWrapper>
        <Header>
          <Button onClick={handleDelete}>Delete Transcription</Button>
          <Button onClick={signOut}>Sign out</Button>
          <input type="text" placeholder="Meeting ID" value={value} onChange={(e)=>setValue(e.target.value)}
        </Header>

Comments

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.