how do I use useCallback hook in svelte

Viewed 48

This is my code block looks line when used with a useCallback hook in react but I want to use same function in svelte,but want to add this in useCallback hook. Is there any alternative for svelte.

const newCancelToken = useCallback(() => {
        axiosSource.current = axios.CancelToken.source();
        return axiosSource.current.token;
    }, []);
1 Answers

Keep that in mind: The way svelte processes its components is very different from react.

React re-renders all components any time any state within a component, or anywhere in a parent, changes. To avoid the re-computation you will need the use of useMemo or useCallback in your case.

Svelte is a compiler and analyzes your template to create targeted DOM update code whenever any concerned state changes. With that in mind, you don't need to memoize such functions with svelte.

Related