You are given a React component AutofocusInput
that renders an input field with a label and a p tag that should display the current input value.
Your task is to implement the functionality where the input field is automatically focused when the component renders, and the input value is updated and displayed as the user types.
Whitespace should be removed from the beginning and end of the input value.
import React, {useState} from 'react'; function InputAutoFocus () { const [inputValue, setInputValue] = useState(''); return ( <div> <label htmlFor="nameInput">Enter your name:</label> <input id="nameInput" data-testid="inputField" type="text" /> <p data-testid="pInputValue">Current value: {inputValue}</p> </div> ); }; export default InputAutoFocus;
Tests