useCallback vs useEffect #249
|
I'd like to know the difference between useCallback vs useEffect and how to use them |
Answered by
whitehorse21
Jun 8, 2023
Replies: 2 comments 1 reply
|
Hi, @highmountaindev109. Good question useEffect(() => { const myFunction = useCallback(() => { |
1 reply
Answer selected by
highmountaindev109
|
Thanks for your interesting discussions guys! @highmountaindev109 @whitehorse21 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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]);