-
-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
forwardRef for button component #341
Comments
I'm wondering if this one can't be solved by implementing the What do you think @tulup-conner ? |
I had a look into the source code, and I guess in order to achieve this we would have to update this part
and if is a button we need to add: |
There is a workaround using a HoC and copying import type { NextPage } from 'next';
import Link from 'next/link';
import { type FC, type ForwardedRef, forwardRef, LegacyRef } from 'react';
import { Button } from 'flowbite-react';
const withRef = <T, P = {}>(
render: FC<P & { ref?: LegacyRef<T> | undefined }>
) =>
Object.assign(
forwardRef<T, P>((props, ref) => render({ ...props, ref })),
render
);
const ButtonWithRef = withRef(Button);
const Home: NextPage = () => {
return (
<Link href="/" passHref>
<ButtonWithRef>Hello World</ButtonWithRef>
</Link>
);
};
export default Home; @rluders If you want, I can provide a PR tomorrow to wrap the component with |
Added forwardRef to button component to work with Next.js' Link component. fix themesberg#341
Is your feature request related to a problem? Please describe.
Seems it's not possible to use buttons with Link component at Next.js
This code throws a warning
Would be good to add forwardRef for button component to increase compatibility with next.js
Describe the solution you'd like
Solution is described at docs https://nextjs.org/docs/api-reference/next/link#if-the-child-is-a-functional-component
The text was updated successfully, but these errors were encountered: