概要
SSR に対応していないコンポーネントをラップする React コンポーネント
Web・アプリ開発計測したスター増加
- 24時間
- 0
- 7日間
- 0
- 15日間
- 0
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナルreact-no-ssr
React component to wrap non SSR components.
When working with Server Side Rendering(SSR) enabled apps, you have to deal with client only components. This wrapper makes it simple to work with those components.
Installation
npm i --save react-no-ssr
Usage
Let's say Comments is our client only component. Now we need to render it only on the client. Here's how we do it.
import React from 'react';
import NoSSR from 'react-no-ssr';
import Comments from './comments.jsx';
const MyPage = () => (
<div>
<h2>My Blog Post</h2>
<hr />
<NoSSR>
<Comments />
</NoSSR>
</div>
);
Then, <Comments /> component is only rendered on the client just after it's mounted. It doesn't render when the SSRed HTML is booting up in the client. So, there won't be any React warning messages on the console.
Render a Component on SSR
Usually, we need to add some loading text or similar until <Comments /> component starts to render. Here's how to do it.
const Loading = () => (<div>Loading...</div>);
const MyPage = () => (
<div>
....
<NoSSR onSSR={<Loading />}>
<Comments />
</NoSSR>
</div>
);
Then <Loading /> component will be rendered until <Comments /> component is rendered to the DOM.
関連プロジェクトを探す
読み込み中…