React
useRef is a React Hook that lets you reference a value that’s not needed for rendering.
export default function App() {
const taskDescriptionInputRef = useRef<HTMLInputElement>(null);
// ...
function handleSubmit() {
if (taskDescriptionInputRef.current && taskDescriptionInputRef.current.value) {
setTasks([...tasks, { id: crypto.randomUUID(), description: taskDescriptionInputRef.current.value, isCompleted: false }]);
taskDescriptionInputRef.current.value = "";
}
}
// ...
return (
<div>
<h1>Todo List</h1>
<div>
<input type="text" placeholder="Add your task" ref={taskDescriptionInputRef} />
<div>
<button onClick={handleSubmit}>Submit</button>
</div>
</div>
{showTasks()}
</div>
);
}⚠️ Opgepast: React → JS(X)-notatie
React Hook Form reduces the amount of code you need to write while removing unnecessary re-renders.
React
Headless UI for building performant and type-safe forms
Waarom TanStack Form? 🤔
Oefening:
npm i @tanstack/react-form
Validaties:
Stap 1: maak een interface die het formulier beschrijft