When Direct Updates Are Fine
What you'll learn: Not every setState call needs the functional update syntax — sometimes the simple direct approach is perfectly safe.
We've spent several lessons drilling into why setState(prev => ...) matters, especially when updates depend on previous state. But here's the good news: you don't always need it. There are plenty of situations where the straightforward setState(newValue) works just fine.
Safe Scenarios for Direct Updates
1. The new value doesn't depend on the old state
If you're setting state based on something completely external — a form input, a prop, a fixed value — there's no closure trap to worry about:
const [username, setUsername] = useState('');
// ✅ Safe: new value comes from the input, not old state
function handleChange(e) {
setUsername(e.target.value);
}
const [status, setStatus] = useState('idle');
// ✅ Safe: just setting a literal value
function startTask() {
setStatus('loading');
}
2. Single update in synchronous flow
If you're only calling setState once per event handler and not chaining multiple updates, direct updates work fine:
const [isOpen, setIsOpen] = useState(false);
// ✅ Safe: one update, no dependency on previous value
function openModal() {
setIsOpen(true);
}
The Simple Rule
Ask yourself: "Does my new state value depend on what the old state value was?" If no, use setState(newValue). If yes, use setState(prev => ...).
Key Takeaway: Direct setState(newValue) is perfectly safe when the new value is independent of the old state or you're making a single update — save functional updates for when you're computing based on previous state or batching multiple changes.