This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const withClientOnlyUser = () => ( | |
<Query query={GET_USER_WITH_ID} ssr={false}> | |
{({ data }) => <span>I won't be run on the server</span>} | |
</Query> | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { renderToStringWithData } from "react-apollo" | |
const client = new ApolloClient(...); | |
renderToStringWithData(App).then((content) => { | |
const initialState = client.extract(); | |
const html = <Html content={content} state={initialState} />; | |
res.status(200); | |
res.send(`<!doctype html>\n${ReactDOM.renderToStaticMarkup(html)}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getDataFromTree } from "react-apollo" | |
app.use((req, res) => { | |
const client = new ApolloClient(...); | |
getDataFromTree(App).then(() => { | |
const content = ReactDOM.renderToString(App); | |
const initialState = client.extract(); | |
const html = <Html content={content} state={initialState} />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Html = ({ content, state }) => ( | |
<html> | |
<body> | |
<div id="root" dangerouslySetInnerHTML={{ __html: content }} /> | |
<script dangerouslySetInnerHTML={{ | |
__html: `window.__APOLLO_STATE__=${JSON.stringify(state).replace(/</g, '\\u003c')};`, | |
}} /> | |
</body> | |
</html> | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CodeSandboxで動かすときにエラーが出たので | |
// babel-polyfillをimportしてる | |
import "babel-polyfill"; | |
import gql from "graphql-tag"; | |
import { ApolloClient } from "apollo-client"; | |
import { ApolloQuery, html } from "lit-apollo"; | |
import { InMemoryCache } from "apollo-cache-inmemory"; | |
import { from } from "apollo-link"; | |
import { HttpLink } from "apollo-link-http"; |
OlderNewer