react-no-ssr

React component to wrap non SSR friendly components

Github星跟蹤圖

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.

主要指標

概覽
名稱與所有者kadirahq/react-no-ssr
主編程語言JavaScript
編程語言JavaScript (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2016-02-19 04:52:04
推送於2024-05-29 14:48:48
最后一次提交2016-04-10 01:10:52
發布數3
最新版本名稱v1.1.0 (發布於 2016-04-10 01:10:15)
第一版名稱v1.0.0 (發布於 )
用户参与
星數453
關注者數6
派生數23
提交數10
已啟用問題?
問題數5
打開的問題數4
拉請求數1
打開的拉請求數2
關閉的拉請求數2
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?