import initArtemis, { ArtemisState } from "./initArtemis"; import Head from "next/head"; import { getDataFromTree } from "react-apollo"; import React from "react"; import { ApolloClient } from "apollo-client"; interface IProps { artemisClient: ApolloClient>; artemisState: ArtemisState; } interface IArtemisMembers { artemisClient: ApolloClient>; } const isBrowser = typeof window !== undefined; export default (App) => { return class Artemis> extends React.Component, {}> { public static displayName = "withArtemis(App)"; public artemisClient: ApolloClient; public static async getInitialProps(ctx) { const { Component, router } = ctx; let appProps = {}; if (App.getInitialProps) { appProps = await App.getInitialProps(ctx); } let artemisState = {}; const artemis = initArtemis(); try { await getDataFromTree( , ); } catch (error) { // tslint:disable-next-line:no-console console.error("Error while running `getDataFromTree`", error); } if (!isBrowser) { // getDataFromTree does not call componentWillUnmount // we need to clear the manually Head.rewind(); } artemisState = artemis.cache.extract(); return { ...appProps, artemisState, }; } constructor(props) { super(props); this.artemisClient = props.artemisClient || initArtemis(props.artemisState); } public render() { return ; } }; };