useCallback vs useEffect #249
-
I'd like to know the difference between useCallback vs useEffect and how to use them |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi, @highmountaindev109. Good question useEffect(() => { const myFunction = useCallback(() => { |
Beta Was this translation helpful? Give feedback.
-
Thanks for your interesting discussions guys! @highmountaindev109 @whitehorse21 |
Beta Was this translation helpful? Give feedback.
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]);