medium10 pts · first answer countsreact-statereact-hooks
Syncing derived values with an effect
What is the best way to improve this component?
const [first, setFirst] = useState('')
const [last, setLast] = useState('')
const [fullName, setFullName] = useState('')
useEffect(() => {
setFullName(first + ' ' + last)
}, [first, last])Discussion 0
Join free to post in the discussion.
Related questions
- Changing a prop inside a childFrontend Developer
- Stale value in useEffectFrontend Developer
- Ref value not shown on screenFrontend Developer
- Resize handler that runs many timesFrontend Developer
- Form keeps the previous user dataFrontend Developer
- Race condition in data fetchingFrontend Developer
- Effect that fetches foreverFrontend Developer
- Tooltip flashes in the wrong placeFrontend Developer