Build a controlled input, store its value in state, and display the character count. The counter must not exceed 32.
Controlled inputs. Manage value via state and show accurate length.
onChange.A card with an input and a character counter (limit 32).
Final result should look like this:

onChange.maxLength={32}.value.length.input DOM component: https://react.dev/reference/react-dom/components/inputimport React, { useState } from 'react';
import './styles.css';
export function TextInputCounter({ placeholder = 'Enter text...' }) {
const [value, setValue] = useState('');
function handleChange(e) {
setValue(e.target.value);
}
return (
<article className="input-card" data-testid="input-card">
<input
className="text-input"
type="text"
placeholder={placeholder}
value={value}
onChange={handleChange}
maxLength={32}
/>
<p className="counter" aria-label="counter">{value.length}</p>
</article>
);
}
export default function App() {
return (
<main className="challenge-container">
<section>
<TextInputCounter />
</section>
</main>
);
}Build a controlled input, store its value in state, and display the character count. The counter must not exceed 32.
Controlled inputs. Manage value via state and show accurate length.
onChange.A card with an input and a character counter (limit 32).
Final result should look like this:

onChange.maxLength={32}.value.length.input DOM component: https://react.dev/reference/react-dom/components/inputimport React, { useState } from 'react';
import './styles.css';
export function TextInputCounter({ placeholder = 'Enter text...' }) {
const [value, setValue] = useState('');
function handleChange(e) {
setValue(e.target.value);
}
return (
<article className="input-card" data-testid="input-card">
<input
className="text-input"
type="text"
placeholder={placeholder}
value={value}
onChange={handleChange}
maxLength={32}
/>
<p className="counter" aria-label="counter">{value.length}</p>
</article>
);
}
export default function App() {
return (
<main className="challenge-container">
<section>
<TextInputCounter />
</section>
</main>
);
}The code editor is intentionally hidden on mobile.
Believe me, it's for the best: I am protecting you from the temptation to code in less-than-ideal conditions. A small screen and a virtual keyboard are not the best tools for a programmer.
📖 Now: Study the task, think through the solution. Act like a strategist.
💻 Later: Sit down at your computer, open the site, and implement all your ideas comfortably. Act like a code-jedi!