next.jssendbird

how to use sendbird-ui kit with next.js


I am trying to integrate https://codesandbox.io/s/3-3-customizing-channellist-sg9kx?file=/src/index.css:0-297 in my next.js project.

I am importing dependencies using:

import dynamic from 'next/dynamic'

const SBProvider = dynamic(
    () => {
        const { SendBirdProvider } = import('sendbird-uikit')
        return SendBirdProvider;
    },
    { ssr: false }
)


const withSendBird = dynamic(
    () => {
        const { withSendBird } = import('sendbird-uikit')
        return withSendBird;
    },
    { ssr: false }
)

as provided in the doc

but still getting this screen shot of the error


Solution

  • I'm sorry to hear you are having a hard time. The code you are looking for would be something like this.

    index.js

    import dynamic from "next/dynamic";
    
    const DynamicAppWithNoSSR = dynamic(() => import("../components/Chat"), {
      ssr: false,
      loading: () => <p>...</p>
    });
    
    const App = () => (
       <div>
          <DynamicAppWithNoSSR />
       </div>
    );
    
    export default App;
    

    Then in Chat.jsx

    import { App } from "sendbird-uikit";
    
    export default () => (
       <div style={{ height: "95vh" }}>
          <App appId="/*your appID*/" userId="/*your userId*/" />
       </div>
    );
    

    You can find a working example here. If you have further questions please feel free to join our Sendbird Community. :)