1.0.6 • Published 3 years ago

@prerendered/client v1.0.6

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

@prerendered/client

**WORK IN PROGRESS**

Instructions

npm install --save @prerendered/client

Example

In the following example, we import the SSRContext which will grab the state from the HTML template for hydration. The useSSR hook can be used to access that data.

If you use Redux or some other state management library, you can access the state with getPrerenderedData and use it to set the app's state.

In your client.js (entrypoint) file, do the following:

// client.js
import React from "react";
import ReactDOM from "react-dom";
import { SSRContext } from "@prerendered/client";
import { App } from "./app";

ReactDOM.hydrate(
  // SSRContext looks for the data from window.__PRERENDERED__
  <SSRContext.Provider>
    <App />
  </SSRContext.Provider>,
  document.getElementById("root")
);

In your app.js file, follow the example below:

// app.js
import React from "react";
import { useSSR } from "@prerendered/client";

export const App = () => {
  const ssrData = useSSR(); // You can now access all the data that was inserted server-side
  return <div>{ssrData.message}</div>;
};
1.0.7-rc1

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago