=
useCallback in React vs. Methods in Vue
React’s useCallback to memoize functions:
javascript
Copy code
import { useState, useCallback } from 'react';
function MyComponent() {
const [count, setCount] = useState(0);
const increment = useCallback(() => {
setCount((prevCount) => prevCount + 1);
}, []);
return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
</div>
);
}
Vue equivalent (methods are automatically cached in Vue):
javascript
Copy code
export default {
data() {
return { count: 0 };
},
methods: {
increment() {
this.count++;
}
}
}
=
No comments:
Post a Comment