As bottom sheet is rendered in a portal internally, using it with SSR frameworks (like Next.js) might be non-straighforward. It cannot be rendered on a server because mounting node haven't been initialized yet, so you have to do it on client only.
You may come up with an initial solution like this:
But this, again, has very frustrating problem: dynamic will replace original ref handler with its custom one, so you won't be able to open sheet programmatically, for instance. Unfortunately, it won't be resolved.
So before I resolve it internally somehow (doesn't look too complicated, or at least I hope so, just a matter of API choice), here's a number of solutions.
Next.js team prepared a great example of implementing modal in their paradigm: link
If you want to use dynamic() anyway, I advise you to create a wrapper around BottomSheet component and then use it:
// BottomSheetWrapper.tsx
import { type Ref } from 'react';
import BottomSheet, {
type BottomSheetRef,
type BottomSheetProps,
} from '@wldyslw/react-bottom-sheet';
import '@wldyslw/react-bottom-sheet/lib/style.css';
As bottom sheet is rendered in a portal internally, using it with SSR frameworks (like Next.js) might be non-straighforward. It cannot be rendered on a server because mounting node haven't been initialized yet, so you have to do it on client only.
You may come up with an initial solution like this:
But it will cause hydration problem as content rendered on client will differ from the pre-rendered on server one.
You may also think of something more advanced like using Next's
dynamic()
function withssr: false
parameter:But this, again, has very frustrating problem:
dynamic
will replace originalref
handler with its custom one, so you won't be able to open sheet programmatically, for instance. Unfortunately, it won't be resolved.So before I resolve it internally somehow (doesn't look too complicated, or at least I hope so, just a matter of API choice), here's a number of solutions.
dynamic()
anyway, I advise you to create a wrapper around BottomSheet component and then use it:const BottomSheetWrapper = ({ sheetRef, ...props }: BottomSheetProps & { sheetRef?: Ref }) => {
return <BottomSheet {...props} ref={sheetRef} />;
};
export default BottomSheetWrapper;