Skip to content

Commit

Permalink
Pass wrapped component's initial props into component heirarchy if th…
Browse files Browse the repository at this point in the history
…ey exist
  • Loading branch information
Adam committed Jan 25, 2017
1 parent e6d777a commit 30de697
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions examples/with-apollo/lib/withData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,7 +33,8 @@ export default (Component) => (
data: state.apollo.data
}
},
headers
headers,
...props
}
}

Expand All @@ -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>
)
}
Expand Down

0 comments on commit 30de697

Please sign in to comment.