All jobs / Frontend / web developer
Frontend / web developer interview question · 1–3 years
Why wrap a handler in useCallback?
The strongest answer
To keep the same function reference between renders when it is passed to a memoised child or listed as an effect dependency; without that, the child re-renders or the effect re-runs every time
Why it works
Right. Reference stability for memo and dependencies.
What a good answer covers
- Stable reference across renders.
- Pairs with React.memo children.
- Dependencies must be listed.
- Skip it where nothing depends on identity.
Answers that fall short
- Close, but not the strongest: To make the function run faster
The function is the same speed. - Weak: Because functions cannot be props otherwise
Any function can be a prop. - Red flag: It is required for all handlers
Only where the reference matters.
Who gets asked this
More Frontend / web developer questions
- The team argues whether a field is `userId` or `user_id`. What is OpenAPI for here?
- When does React.memo help, and when does it not?
- The register API can fail because the email is taken or because the password is too short. What should the UI…
- The app feels sluggish when typing in one field. How do you find the cause?
- Where should state live, as a rule?
- Why do teams use a server-state library instead of useEffect plus useState for data?
- Choosing between client rendering, server rendering, static generation and streaming for a new product — how…
- A 400-component app has become impossible to change safely. What structural move do you make first?