Skip to content

Commit a76ec83

Browse files
adamsofferrauchg
authored andcommitted
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
1 parent b4e2b7b commit a76ec83

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

examples/with-apollo/lib/withData.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ export default (Component) => (
1111
const client = initClient(headers)
1212
const store = initStore(client, client.initialState)
1313

14+
const props = {
15+
url: { query: ctx.query, pathname: ctx.pathname },
16+
...await (Component.getInitialProps ? Component.getInitialProps(ctx) : {})
17+
}
18+
1419
if (!process.browser) {
1520
const app = (
1621
<ApolloProvider client={client} store={store}>
17-
<Component url={{ query: ctx.query, pathname: ctx.pathname }} />
22+
<Component {...props} />
1823
</ApolloProvider>
1924
)
2025
await getDataFromTree(app)
@@ -28,7 +33,8 @@ export default (Component) => (
2833
data: state.apollo.data
2934
}
3035
},
31-
headers
36+
headers,
37+
...props
3238
}
3339
}
3440

@@ -41,7 +47,7 @@ export default (Component) => (
4147
render () {
4248
return (
4349
<ApolloProvider client={this.client} store={this.store}>
44-
<Component url={this.props.url} />
50+
<Component {...this.props} />
4551
</ApolloProvider>
4652
)
4753
}

0 commit comments

Comments
 (0)