Skip to content

useCallback vs useEffect #249

Closed Answered by whitehorse21
highmountaindev109 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @highmountaindev109. Good question
The main difference between useCallback and useEffect is that useCallback is used to memoize a function instance, while useEffect is used to manage side effects.

useEffect(() => {
// execute when state changed
() => {
// execute before state is changed
}
}, [state]);

const myFunction = useCallback(() => {
// execute your logic for myFunction
}, [state]);

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@devenes
Comment options

Answer selected by highmountaindev109
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants