Skip to main content
100%

Bats plus React useMemo

✓ Published1🌍 Public
Bbrandon flowers
Last edited Mar 3, 2020
Created on Mar 1, 2020

This example shows how React useMemo controls component re-rendering in a data visualization of bat icons moving across a screen. Six bat elements are rendered from an array of bat data objects, with each bat displaying its name and position. The app uses React's useState, useEffect, useRef, and useMemo hooks to isolate updates so only the bat whose data changes moves, while others remain static. A performance timer measures blocking computations from the intensive.js module, and the interface includes a table of bat data and a reset button. The visualization demonstrates that useMemo prevents unnecessary re-renders when dependencies remain unchanged.

AI-generated description

Experiment with React useMemo

With useMemo, the components will only get updated if their data changes. In this case, the data is an array. If useMemo takes in this array, all the bats will update on a change instead of the desired one bat.

MIT Licensed

Similar vizzes