我正在尝试一个想法,以Gatsby为基础,创建一个混合了静态和动态内容的网站。这个混合站点将包含对公众可用的静态营销页面,以及存在于身份验证墙后面的几个动态页面。根据this tweet with @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站点中,站点的根在哪里呢?
发布于 2017-08-08 02:12:45
您想要做一些类似于Redux示例站点的事情
https://github.com/gatsbyjs/gatsby/blob/master/examples/using-redux/gatsby-browser.js
您需要注意的一件事是,在使用来自Graph.cool的数据之前,请始终检查您是否在客户端。如果您正在使用将静态呈现的组件,则不能期望graph.cool数据可用,因为该组件将呈现在服务器和客户端上。
发布于 2017-10-30 15:43:15
您可以通过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>
);
}
}https://stackoverflow.com/questions/45552697
复制相似问题