Rajesh Naroth
1 min readAug 14, 2019

--

Hey Murali,

Thanks for chipping in. You’re correct. Moving the throttled function outside the component will solve the issue. I’m sure some might find this solution simpler and adequate. My goal here was to make it work inside the functional component.

Traditionally we’ve used refs for DOM references. useRef() hook provides you more than that. Here is a quote from the React site:

However, useRef() is useful for more than the ref attribute. It’s handy for keeping any mutable value around similar to how you’d use instance fields in classes.

This works because useRef() creates a plain JavaScript object. The only difference between useRef() and creating a {current: ...} object yourself is that useRefwill give you the same ref object on every render.

Cheers.

--

--

Rajesh Naroth
Rajesh Naroth

Written by Rajesh Naroth

Frontend Architect, San Jose, CA

No responses yet