@gottfired Simply adding onMouseMove will work but it will end up a performance issue due to frequent garbage collections. please refer the usehooks.com/useEventListener/ code for more details.
To be honest with a simple onMouseMove there is no performance penalty at all, but sure adding an event listener avoids synthetic events. But in that case I'd not cite the code of useEventListener() as part of the overhead, since you'd simply use that hook when you want to add an event listener. That would be like adding the compiler code for on:mousemove from svelte as overhead to the svelte implementation. Not that I'm in any way against svelte. I think that direct dom manipulation definitely has a future, but I think the comparison should be fair.
Agreed with you, We can use the 3rd party useEventListener hook. but how do we know that we need useEventListener hook? Also, this is a generic problem so we can find 3rd party hooks, what if you have a complex ui that needs to be developed by yourself, you'll end up using useCallback, useMemo, useImperativeHandle etc., right?. This is what I'm trying to convey here, if you need a high performance react app, you'll need additional learning and time apart from your application development and you'll end up with less readable code. Svelte completely removes all of the unnecessary boilerplates like useState, useRef, useCallback, useMemo etc., from our application logic.
Agreed. When I transitioned to hooks from class components it took a while to wrap my head around the concept. But now I find it very powerful, since it easily allows separation of component logic and rendering and improved React code reuse a lot. I'll keep an eye on svelte and also solid, which also looks very promising and imho easier to transition to as a react developer than svelte which gives me Angular (shudder) vibes.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
@gottfired Simply adding onMouseMove will work but it will end up a performance issue due to frequent garbage collections. please refer the usehooks.com/useEventListener/ code for more details.
To be honest with a simple onMouseMove there is no performance penalty at all, but sure adding an event listener avoids synthetic events. But in that case I'd not cite the code of useEventListener() as part of the overhead, since you'd simply use that hook when you want to add an event listener. That would be like adding the compiler code for on:mousemove from svelte as overhead to the svelte implementation. Not that I'm in any way against svelte. I think that direct dom manipulation definitely has a future, but I think the comparison should be fair.
Agreed with you, We can use the 3rd party useEventListener hook. but how do we know that we need useEventListener hook? Also, this is a generic problem so we can find 3rd party hooks, what if you have a complex ui that needs to be developed by yourself, you'll end up using useCallback, useMemo, useImperativeHandle etc., right?. This is what I'm trying to convey here, if you need a high performance react app, you'll need additional learning and time apart from your application development and you'll end up with less readable code. Svelte completely removes all of the unnecessary boilerplates like useState, useRef, useCallback, useMemo etc., from our application logic.
Agreed. When I transitioned to hooks from class components it took a while to wrap my head around the concept. But now I find it very powerful, since it easily allows separation of component logic and rendering and improved React code reuse a lot. I'll keep an eye on svelte and also solid, which also looks very promising and imho easier to transition to as a react developer than svelte which gives me Angular (shudder) vibes.