You are given a React component CharacterCounter that renders an input field and displays a character count.
Your task is to implement the functionality where the input is limited to a maximum number of characters, and the current character count is displayed and updated as the user types.
CharacterCounter
.1[Input field with "Hello, World!"]
213 / 20
3
1[Input field with " Hello, World! "]
215 / 20
3
import React, {useState} from 'react'; const CharacterCounter = () => { const [inputValue, setInputValue] = useState(''); const maxChars = 20; return ( <div> <input data-testid="input" type="text" value={inputValue} /> <p data-testid="char-count">0 / {maxChars}</p> </div> ); }; export default CharacterCounter;
Tests