如何在next.js中使用sendbird-ui工具包

我正在尝试将https://codesandbox.io/s/3-3-customizing-channellist-sg9kx?file=/src/index.css:0-297集成到我的next.js项目中。

我正在使用以下方式导入依赖项:

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 }
)

文档中提供的

但是仍然得到这个 screen shot of the error

huazhua88225 回答:如何在next.js中使用sendbird-ui工具包

尝试:

import dynamic from 'next/dynamic'

const DynamicUIKit = dynamic(() => import("sendbird-uikit"))

export default function Home() {
  return (
      <div>
        <DynamicUIKit appId="YOUR-APP-ID" userId="test1" />
      </div>
  )
}

您需要导入CSS(请参见下文)

如果从此处创建应用程序开始: https://nextjs.org/learn/basics/create-nextjs-app

确保它可以工作。然后安装UIKit:

npm install sendbird-uikit --save

在您的index.js中

import { App as SendBirdApp } from "sendbird-uikit";
export default function Home() {
  return (
      <div>
        <SendBirdApp appId="YOUR-APP-ID" userId="ANY-USER-ID" />
      </div>
  )
}

您必须创建_app.js才能包含此CSS:

import "sendbird-uikit/dist/index.css"; 

documentation

,

很抱歉听到您遇到困难。您正在寻找的代码将是这样的。

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;

然后在Chat.jsx中

import { App } from "sendbird-uikit";

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

您可以找到一个有效的示例here。如果您还有其他疑问,请随时加入我们的Sendbird Community。 :)

本文链接:https://www.f2er.com/1346272.html

大家都在问