get-loadables-and-graphql

1.0.3 • Public • Published

npm

Package was built to have unanimous capability to use react-apollo and loadable-components while approaching ssr.

Follow setups required for react-apollo and loadable-components.

Install using:

npm install get-loadables-and-graphql

After having followed setup for react-apollo and loadable-components

import GetLoadableAndGraphqlData from 'get-loadables-and-graphql';

// Code needed - middlewares
const appComponent = (
  <ApolloProvider client={ apolloClient }>
    <App
      />
  </ApolloProvider>
);

const loadableScripts = await GetLoadableAndGraphqlData( appComponent );
const app = ReactDOM.renderToString( appComponent );
const initialState = apolloClient.extract();

const html  = `
  <html>
    <body>
      <script
        dangerouslySetInnerHTML={ {
          __html: this.props.loadableScripts,
        } }
        />
      <script
        dangerouslySetInnerHTML={ {
          __html: `window.__APOLLO_STATE__=${ JSON.stringify( this.props.initialState ).replace( /</g, '\\u003c' ) };`,
        } }
        />
    </body>
  </html>
`;

Package Sidebar

Install

npm i get-loadables-and-graphql

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

5.81 kB

Total Files

4

Last publish

Collaborators

  • ajith.sakharia