/performance-and-polling

Using React library: Need tips to perform your components client side (memoize,useMemo,memo,useCallback,virtualized list) components,)?, need to know how to iterate an api request client side? Check here some good practices.

Primary LanguageTypeScript

NextJS, React, Quirrel, Redis

1. Optimizing Performance in React JS for Handling Massive Data

Utilize useMemo

The useMemo hook can be employed to memoize expensive computations and prevent redundant recalculations. By selectively caching values, you can avoid unnecessary overhead and enhance rendering speed.

Employ React.memo

The React.memo higher-order component can be applied to functional components. It enhances performance by avoiding re-renders when the component's props remain unchanged. This is particularly useful when rendering large lists of similar items.

useCallback

With the useCallback hook, you can optimize the creation of callback functions. This is especially beneficial when passing callbacks as props to child components, as it ensures these functions don't get recreated needlessly during re-renders.

What are Virtualized Lists and why could be good to use them?

For rendering extensive lists, employing virtualization techniques like the "Virtualized List" strategy can significantly improve performance. This approach efficiently renders only the items currently visible in the viewport, reducing the strain on the browser.

2.Efficient Client-Side Polling (In this project I setup a ticket platform using Redis, Quirrel, Nextjs and React.)

Use setInterval and clearInterval

For periodic polling, setInterval can be used to execute a function at defined intervals. Don't forget to clear the interval with clearInterval when it's no longer needed, preventing memory leaks.

Leverage the useEffect Hook

The useEffect hook is ideal for managing side effects like polling. It can be set up to run the polling logic, and you can control its behavior by specifying dependencies and cleanup procedures.