[RAC] - using useContextProps without ref ?
#8080
-
|
Hey there, I was implementing a Check icon in the const ListBoxItem = (props: ListBoxItemProps) => {
const { className, ...rest } = props;
return (
<ListBoxItemPrimitive
className={composeRenderProps(className, (className, renderProps) =>
listboxVariants().listboxItem({
...renderProps,
className,
})
)}
// I want to show a Check icon here alongside children if it's selected
{...rest}
/>
);
};I did check the Accessing state section as well but looks like there's no I hope I'm on the right path, is adding ref the only option left here for now? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I'm doing it using render props for now, but curious to know if it's the ideal way - less code and more performant? const ListBoxItem = (props: ListBoxItemProps) => {
const { className, children, ...rest } = props;
return (
<ListBoxItemPrimitive
className={composeRenderProps(className, (className, renderProps) =>
listboxVariants().listboxItem({
...renderProps,
className,
})
)}
{...rest}
>
{({ isSelected }) => (
<>
{children}
{isSelected && <RiCheckLine className="ml-auto" />}
</>
)}
</ListBoxItemPrimitive>
);
}; |
Beta Was this translation helpful? Give feedback.
You could just get the Context without using
useContextProps.Or you could use CSS to display: none/whatever based on the group + data-attribute?
We might be able to support smaller subset of the state, if I recall, there was an issue with the collection being in the state and that caused an infinite loop.