You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all, I want to make a dropdown component that will accept any, custom react component or string as a control. For example I want to pass my custom button
export const DropDown = memo((props: DropDownProps) => {
const { className, list, children } = props
const clsDropDown = classNames(cls.dropDown, [className], {})
return (
<div className={clsDropDown}>
<Menu>
<Menu.Button as={Fragment}>{children}</Menu.Button>
<Menu.Items>
{list.map((item) => (
/* Use the `active` state to conditionally style the active item. */
<Menu.Item key={item.id} as={Fragment}>
{item.Component}
</Menu.Item>
))}
</Menu.Items>
</Menu>
</div>
)
})
But in this case I get an error in the browser Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
This is what the code for my custom button looks like right now
I additionally used forwardRef but that didn't help
I would like to make a universal dropdown and pass different components to it, can you please tell me how to do it correctly?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all, I want to make a dropdown component that will accept any, custom react component or string as a control. For example I want to pass my custom button
And here is the code for the DropDown component
But in this case I get an error in the browser
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
This is what the code for my custom button looks like right now
I additionally used forwardRef but that didn't help
I would like to make a universal dropdown and pass different components to it, can you please tell me how to do it correctly?
Beta Was this translation helpful? Give feedback.
All reactions