Make it possible for interactions hooks to not update state and thereby not triggering rerenders #3193
Replies: 1 comment 1 reply
-
We do a lot with the state of interactions in order to set the correct accessibility, I'm not sure we could do something like this because then there'd be no updates to the rendered component. Can you explain more about your use case? Maybe I'm missing something. To give you an idea of where we're coming from, here are some examples of what we do with state in aria currently. We need to potentially merge ids and cause a re-render, so we track that in state. If focus is visible is another one we track in aria. There may also be behavioral differences. For instance, we might have a different screen reader announcement for someone using a mouse vs using a keyboard, it's information that is tracked in a hook and is rendered to the screen on a specific element. When the interaction mode changes, we need to make sure that the element is re-rendered to reflect that. Or in the case of NumberFields, we only want to enable the mouse wheel spin when focus is within the field. https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/numberfield/src/useNumberField.ts#L123 |
Beta Was this translation helpful? Give feedback.
-
@devongovett
Make it possible for interaction hooks to not update state and thereby not triggering rerenders because in my case I only use the interactions hooks for assigning data attributes to the underlying elements by using refs so I can target them through CSS and so it would be more performant because no react renders will occur.
My proposal is that interaction hooks that trigger rerender should have an option to not use setState inside the hook this update would not require breaking changes.
Beta Was this translation helpful? Give feedback.
All reactions