0.0.1 • Published 5 years ago
@mizchi/ssr-helpers v0.0.1
@mizchi/ssr-helpers
Implement react-cache
SSR helpers.
Requirements
- react: ^16.7
- react-dom: ^16.7
- regenerator-runtime(included babel-polyfill)
Data fetcher
import { renderAsync, createResource } from "@mizchi/ssr-helpers";
// data fetcher
const resource = createResource(async () => {
await new Promise(r => setTimeout(r, 1000));
return { message: "hello" };
});
function App() {
const data = resource.read();
return <div>{data.message}</div>;
}
const html = await renderAsync({
tree: <App />
});
Client rendering
import React from "react";
import ReactDOM from "react-dom";
const root = document.querySelector(".root") as HTMLDivElement;
ReactDOM.hydrate(
<Suspense fallback="loading">
<App />
</Suspense>,
root
);
How to dev
yarn dev
: Start application server onhttp://localhost:1234
yarn build
: Generatedist
yarn test
: Run jestyarn deploy
: Deploy to netlify (need netlify account)
LICENSE
MIT
0.0.1
5 years ago