2017-08-07 50 views
3

我正在嘗試創建一個將靜態和動態內容混合使用的網站,使用Gatsby作爲基礎。這個混合網站將包含可供公衆使用的靜態營銷頁面以及存在於認證牆背後的若干動態頁面。根據this tweet with @Gatsby,這是可行的。如何將蓋茨比混合型站點連接到Apollo/Graphcool(或Redux)?

我被困在第1步,添加一個apollo提供程序,將該站點連接到Graphcool。

通常情況下,我會做這樣的根像這樣,在應用程序是我的網站的根......

const networkInterface = createNetworkInterface({ 
    uri: GRAPHCOOL_SIMPLE_ENDPOINT 
}); 

const client = new ApolloClient({ 
    networkInterface 
}); 

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

但是,在將網站的根是在蓋茨比的網站?

回答

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