Side effects in `useMemo` in `useRowSelect` plugin
See original GitHub issueI decided to pull this out of #2120 to give it proper focus, and also because if 2120 gets resolved in another way, I believe it is still important to see this fixed.
Describe the bug (required)
The useRowSelect plugins incurs side effects in a useMemo
call.
This violates the useMemo
pattern, and is the probable root cause for varied desynchronization and re-rendering rendering issues (eg #2159, #2120).
Provide an example via Codesandbox! (required)
See related bugs. Perhaps this is the simplest form, though its simplicity needs React.Strict to trigger a break.
In more complex code, it manifests itself as isSelected
/selectedFlatRows
desynchronization.
Steps To Reproduce
- Go to useRowSelect.js:181.
- Notice the lines that have side effects.
row.isSelected = !!isSelected row.isSomeSelected = isSelected === null
Expected behavior
I see two possible approaches:
- Better: properly derive
isSelected
fromselectedRowIds
(that is, makeisSelected
a useMemo with dependency onselectedRowIds
) - Alternative: explore
useLayoutEffect
instead? Sounds kludgy.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:7
Top Results From Across the Web
Side effects in useMemo in useRowSelect plugin #2170
The useRowSelect plugins incurs side effects in a useMemo call. This violates the useMemo pattern, and is the probable root cause for varied ......
Read more >React.useMemo and when you should use it - everyday.codes
The only difference is that useEffect is intended for side-effects (hence the name), while functions in useMemo are supposed to be pure and ......
Read more >API Reference: Overview - React Table - TanStack
React Table relies on memoization to determine when state and side effects should update or be calculated. This means that every option you...
Read more >react-table - npm
React Table relies on memoization to determine when state and side effects should update or be calculated. This means that every option you ......
Read more >Changing column width in react-table - Stack Overflow
You need to use a layout hook (useBlockLayout, useAbsoluteLayout or useFlexLayout) so the specified width is applied.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The amount of people running into this as of today are very few, and seeing how the issue will disappear in the next version, I don’t see a big pressing issue to fix this. That said, if the number of people experiencing this issue increases dramatically I will look into fixing it in v7. As always anyone coming across the this issue that wants to fix it is more than welcome to open a PR and I would be happy to guide them along the way.
I ran into this issue today as well, was quite confused until I found this issue. perhaps it could be mentioned in documentation as a known issue until it’s fixed?