mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Update Apollo Example (#888)
* Add minimal apollo example * Update apollo example README * Update apollo example demo link in README * Fix button styles * Fix show more button * Alias demo url * Include the data field on the Apollo store when hydrating * Revert * Include the data field on the Apollo store when hydrating per tpreusse's suggestion. * Add example to faq section in README * Sort by newest; Add active state to buttons * Make optimization suggestions * Use process.browser; inline props * Pass wrapped component's initial props into component heirarchy if they exist
This commit is contained in:
parent
b4e2b7bd4d
commit
a76ec83b64
|
@ -11,10 +11,15 @@ export default (Component) => (
|
|||
const client = initClient(headers)
|
||||
const store = initStore(client, client.initialState)
|
||||
|
||||
const props = {
|
||||
url: { query: ctx.query, pathname: ctx.pathname },
|
||||
...await (Component.getInitialProps ? Component.getInitialProps(ctx) : {})
|
||||
}
|
||||
|
||||
if (!process.browser) {
|
||||
const app = (
|
||||
<ApolloProvider client={client} store={store}>
|
||||
<Component url={{ query: ctx.query, pathname: ctx.pathname }} />
|
||||
<Component {...props} />
|
||||
</ApolloProvider>
|
||||
)
|
||||
await getDataFromTree(app)
|
||||
|
@ -28,7 +33,8 @@ export default (Component) => (
|
|||
data: state.apollo.data
|
||||
}
|
||||
},
|
||||
headers
|
||||
headers,
|
||||
...props
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +47,7 @@ export default (Component) => (
|
|||
render () {
|
||||
return (
|
||||
<ApolloProvider client={this.client} store={this.store}>
|
||||
<Component url={this.props.url} />
|
||||
<Component {...this.props} />
|
||||
</ApolloProvider>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue