useCallback
React 122 characters
// This function (component) is executed on every render
function Component() {
// this event handler is redefined on every render
const handleClick = () => alert("hello")
// because `handleClick` is redefined on every render, `ChildComponent` will be re-rendered too. Because its `onClick` prop is considered changed.
return <ChildComponent onClick={handleClick} />
}
Svelte 19 characters (84% less)
<script>
// In Svelte this isn't needed, because event handlers are declared inside <script> tags.
// They aren't defined in the render path and therefore aren't redefined on every render.
// They are defined once per component, so they work similar to how event handlers worked with React.Component.
</script>