Skip to content

Commit

Permalink
Merge pull request #1 from maapteh/feature/fallback-api
Browse files Browse the repository at this point in the history
Feature/fallback api
  • Loading branch information
maapteh authored Nov 24, 2019
2 parents fa7833e + 4fe1b15 commit 93c20fb
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ yarn-error.log
node_modules

coverage
dist
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Loading = () => (<div>Loading...</div>);
const Page = () => (
<>
....
<NoSSR onSSR={<Loading />}>
<NoSSR fallback={<Loading />}>
<Foo />
</NoSSR>
</>
Expand Down
13 changes: 0 additions & 13 deletions dist/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mpth/react-no-ssr",
"version": "0.0.8",
"version": "1.0.0",
"description": "React component to wrap non SSR components.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('NoSSR Component', () => {
const Loading = () => <div>Loading...</div>;

it('should render correctly with custom loading', () => {
const markup = ReactDOMServer.renderToStaticMarkup(<NoSSR onSSR={<Loading />}>
const markup = ReactDOMServer.renderToStaticMarkup(<NoSSR fallback={<Loading />}>
<MyComp />
</NoSSR>);
expect(markup).toBe('<div>Loading...</div>')
Expand Down
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import * as React from 'react';

interface Props {
children: any; // React.ReactNode
onSSR?: any; // JSX.Element
fallback?: any; // JSX.Element
}

const NoSSR = ({ children, onSSR = null }: Props) => {
const NoSSR = ({ children, fallback = null }: Props) => {
const [render, setRender] = React.useState(false);

React.useEffect(() => setRender(true), []);

if (!render) {
return onSSR;
return fallback;
}

return children;
Expand Down

0 comments on commit 93c20fb

Please sign in to comment.