You are viewing documentation for a previous version of this software.

Switch to the latest stable version.

@apollo/react-ssr

API reference


Installation

Text
1npm install @apollo/react-ssr

getDataFromTree

The getDataFromTree function takes your React tree, determines which queries are needed to render them, and then fetches them all.

Params

ParamTypedescription
treeReact.ReactNodeThe React tree you would like to render and fetch data for.
context{ [key: string]: any }Optional values you would like to make available in the React Context during rendering / data retrieval.

Result

getDataFromTree returns a promise (Promise<string>) which resolves when the data is ready in your Apollo Client store. The result is generated using ReactDOMServer.renderToStaticMarkup under the hood.

Example

Refer to the Using getDataFromTree section of the docs.

renderToStringWithData

The renderToStringWithData function is similar to getDataFromTree, but uses ReactDOMServer.renderToString to render its result instead of ReactDOMServer.renderToStaticMarkup (the React docs help explain the difference).

Params

ParamTypedescription
componentReactElement
The React component tree you would like to render and fetch data for.

Result

renderToStringWithData returns a promise (Promise<string>) which resolves when the data is ready in your Apollo Client store. The result is generated using ReactDOMServer.renderToString under the hood.

Example

Refer to the Using renderToStringWithData section of the docs.

Feedback

Edit on GitHub

Forums