Help needed handling 1k react checkboxes
if I have a state of arrays that has all the selected users id and I have 1000 users and when a user is selected there is lag how would I handle that my current handleUserSelected code:
13 Replies
useMemo
if you are doing a heavy rendering, you can try to use millionjs
Million.js
The Virtual DOM Replacement for React
Jack Herrington
YouTube
Single Line React Performance Boost with Million
Turbo charge your React application with the new block rendering engine in Million.
Code: https://github.com/jherr/million-rainbow/blob/main/src/App.tsx
Liminal: https://www.liminal.sh/
Fireship
YouTube
High-school student makes React a million times faster
Million.js is a React library that can improve rendering performance by bypassing the virtual DOM. It is inspired by blockdom and other popular JavaScript frameworks like Solid and Svelte
#javascript #programming #thecodereport
💬 Chat with Me on Discord
https://discord.gg/fireship
🔗 Resources
Million on GitHub https://github.com/aidenybai/...
lol I saw milion a while ago
ill have to try memo
if I use useMemo how would I pass down value: string that comes from the component checkbox
yeah i also tried million it does not work faster
well it prob does but the state chanes still take alot of time
If there is a 1000 checkboxes at once it is very unlikely that the user needs to see 1000 on the page at once.
You can use virtualization to only show a portion at a time
I found an example with checkboxes that may help
GitHub
GitHub - emilebres/react-virtualized-checkbox: Checkbox group compo...
Checkbox group component with virtualization for large number of options - GitHub - emilebres/react-virtualized-checkbox: Checkbox group component with virtualization for large number of options
GitHub
GitHub - bvaughn/react-virtualized: React components for efficientl...
React components for efficiently rendering large lists and tabular data - GitHub - bvaughn/react-virtualized: React components for efficiently rendering large lists and tabular data
But you are pretty much looking for a virtualized list or something similiar
https://emilebres.github.io/react-virtualized-checkbox/
I’ll check it out thanks
imo the obvious solution is just throw tanstack virtual into your list renderer and call it a day
https://tanstack.com/virtual/v3/docs/guide/introduction
Introduction | TanStack Table Docs
TanStack Virtual is a headless UI utility for virtualizing long lists of elements in JS/TS, React, Vue, Svelte and Solid. It is not a component therefore does not ship with or render any markup or styles for you. While this requires a bit of markup and styles from you, you will retain 100% control over your styles, design and implementation.
T...
if u want some further optimisation i'd store the selected state in a set instead of an array, u just gotta be careful around immutability with that
ima try virtualation lets see
It worked
thanks