-
-
Notifications
You must be signed in to change notification settings - Fork 413
Open
Description
| scrollMargin: listRef.current?.offsetTop ?? 0, |
Error: Cannot access refs during render
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef).
...
> 15 | scrollMargin: listRef.current?.offsetTop ?? 0
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ Cannot access ref value during render
(react-hooks/refs)
I tried:
scrollMargin: 0- this causes problems because now my list of accordions is not shifting when accordion is expanded- I tried 1. and also adding a
useEffect/useLayoutEffectto changevirtualizer.options.scrollMarginwheneverlistRefis set but then I get another error :However I'm currently updating that value like so inError: This value cannot be modified Modifying a value returned from a hook is not allowed. Consider moving the modification into the hook where the value is constructed. (react-hooks/immutability)useLayoutEffectand it works without ESLint errors but I think ESLint might just be not seeing it - this is my current working setup (accordions expand, the elements move down to make space but I do have the react-hooks/refs error):new ResizeObserver(() => { virtualizer.options.scrollMargin = listRef.current!.offsetTop })
Metadata
Metadata
Assignees
Labels
No labels