Git Product home page Git Product logo

maapteh / react-no-ssr Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 0.0 358 KB

Simple component for not rendering its children on the server, option to have loading component `@mpth/react-no-ssr`. Another module is available where you can load children when they come into view: `@mpth/react-in-view`

Home Page: https://www.npmjs.com/package/@mpth/react-no-ssr

License: MIT License

JavaScript 25.33% TypeScript 74.67%
react hooks-api-react component typescript

react-no-ssr's Introduction

@mpth/react-no-ssr

React component to wrap non SSR components, speeding up the eventloop while rendering pages SSR. Works with React >= 16.5.0

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. npmjs.com/package/@mpth/react-no-ssr

Installation

yarn add @mpth/react-no-ssr

Usage

Foo is our client only component:

import React from 'react';
import NoSSR from '@mpth/react-no-ssr';
import Foo from '../modules/foo';
import Bar from '../modules/bar';

const Page = () => (
  <>
    <h1>Page</h1>
    <Bar />
    <NoSSR>
      <Foo />
    </NoSSR>
  </>
);

Then, <Foo /> component is only rendered on the client just after it's mounted.

Render a Component on SSR

Usually, we need to add some loading text or similar until <Foo /> component starts to render. Here's how to do it.

const Loading = () => (<div>Loading...</div>);
const Page = () => (
  <>
    ....
    <NoSSR fallback={<Loading />}>
      <Foo />
    </NoSSR>
  </>
);

Now <Loading /> component will be rendered until <Foo /> component is rendered to the DOM.

Codecov Coverage

react-no-ssr's People

Contributors

dependabot[bot] avatar maapteh avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-no-ssr's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update testing-library monorepo (@testing-library/jest-dom, @testing-library/react, @testing-library/react-hooks)
  • Update actions/cache action to v4
  • Update actions/checkout action to v4
  • Update actions/setup-node action to v4
  • Update codecov/codecov-action action to v4
  • Update dependency eslint to v9
  • Update dependency eslint-config-airbnb to v19
  • Update dependency eslint-config-prettier to v9
  • Update dependency eslint-plugin-prettier to v5
  • Update dependency prettier to v3
  • Update dependency rimraf to v5
  • Update dependency typescript to v5
  • Update github/codeql-action action to v3
  • Update jest monorepo to v29 (major) (@types/jest, jest, ts-jest)
  • Update react monorepo to v18 (major) (react, react-dom)
  • Update testing-library monorepo (major) (@testing-library/jest-dom, @testing-library/react, @testing-library/react-hooks)
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/blank.yml
  • actions/checkout v2
  • actions/setup-node v1
  • actions/cache v2
  • codecov/codecov-action v1
.github/workflows/codeql-analysis.yml
  • actions/checkout v2
  • github/codeql-action v1
  • github/codeql-action v1
  • github/codeql-action v1
.github/workflows/npm-publish.yml
  • actions/checkout v1
  • actions/setup-node v1
  • actions/cache v2
npm
package.json
  • @testing-library/jest-dom 5.0.2
  • @testing-library/react 10.4.3
  • @testing-library/react-hooks 3.2.1
  • @types/jest 24.9.1
  • @typescript-eslint/parser 2.34.0
  • eslint 6.8.0
  • eslint-config-airbnb 18.2.0
  • eslint-config-prettier 6.9.0
  • eslint-plugin-import 2.20.0
  • eslint-plugin-jsx-a11y 6.2.3
  • eslint-plugin-prettier 3.1.3
  • eslint-plugin-react 7.18.0
  • eslint-plugin-react-hooks 4.0.4
  • jest 24.9.0
  • jsdom 16.0.1
  • prettier 2.0.5
  • react 16.12.0
  • react-dom 16.12.0
  • rimraf 3.0.2
  • ts-jest 25.5.1
  • typescript 3.7.5
  • react >16.5.0

  • Check this box to trigger a request for Renovate to run again on this repository

will this work with nextjs and razzlejs

I'm very impressed by the simplicity of this compared to dynamic module load alternatives to ive been looking at top achieve something similar.

will it "just work" with any SSR libraries like Next.js and Razzle.js?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.