如何将Gatsby混合站点连接到Apollo/Graphcool(或Redux)?

3
我正在尝试一个创意,创建一个混合静态和动态内容的站点,使用Gatsby作为基础。这个混合站点将包含对公众可用的静态营销页面以及几个存在于身份验证墙后面的动态页面。根据@Gatsby的这条推文,这是可行的。
我卡在第一步,添加一个Apollo提供程序,将站点连接到Graphcool。
通常,我会在根目录下执行此操作,如下所示,其中App是我的站点的根...
const networkInterface = createNetworkInterface({
  uri: GRAPHCOOL_SIMPLE_ENDPOINT
});

const client = new ApolloClient({
  networkInterface
});

export default ReactDOM.render(
  <ApolloProvider client={client}>
    <App />
  </ApolloProvider>,
  document.getElementById('root')
);

在 Gatsby 网站中,网站的根目录在哪里呢?
2个回答

3

0

您可以通过 componentDidMount 生命周期方法设置客户端组件。例如:

class Index extends React.Component<IndexPageProps> {
  public componentDidMount(): void {
    ReactDOM.render(<App />, document.getElementById('root'));
  }

  public render(): JSX.Element {
    return (
      <div>
        <div id="root" />
      </div>
    );
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接