Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withDisabledSSR component #55

Merged
merged 6 commits into from Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/styleguide.config.json
Expand Up @@ -76,7 +76,8 @@
"name": "Higher Order Components",
"directory": "hocs",
"items": [
"withTimeoutFallback"
"withTimeoutFallback",
"withDisabledSSR"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/build/1.3351bd93.js → docs/build/1.983a8b97.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>react-common</title><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Rubik:400,700"></head><body><div id="rsg-root"></div><div id="app"></div><script src="build/bundle.20e72f92.js"></script></body></html>
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>react-common</title><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Rubik:400,700"></head><body><div id="rsg-root"></div><div id="app"></div><script src="build/bundle.c00ec238.js"></script></body></html>
1 change: 1 addition & 0 deletions source/hocs/index.js
Expand Up @@ -6,3 +6,4 @@

// eslint-disable-next-line
export { default as withTimeoutFallback } from './withTimeoutFallback';
export { default as withDisabledSSR } from './withDisabledSSR';
16 changes: 16 additions & 0 deletions source/hocs/withDisabledSSR/README.md
@@ -0,0 +1,16 @@
Only render a component on the browser


## Usage

```js static
import withDisabledSSR from '@react-common/hocs/withDisabledSSR';

const Component = props => (<div> ...spinner </div>)
const ComponentWithDisabledSSR = withDisabledSSR(Component);

// Usage
<ComponentWithDisabledSSR />
```


11 changes: 11 additions & 0 deletions source/hocs/withDisabledSSR/__snapshots__/index.spec.js.snap
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Component without SSR 1`] = `
<DisabledSSRComponent>
<TestComponent>
<div>
...spinner
</div>
</TestComponent>
</DisabledSSRComponent>
`;
25 changes: 25 additions & 0 deletions source/hocs/withDisabledSSR/index.js
@@ -0,0 +1,25 @@
import React from 'react';

function withDisabledSSR(WrappedComponent) {
class DisabledSSRComponent extends React.Component {
state = {
shouldRender: false,
};

componentDidMount() {
this.setState({ shouldRender: true });
}

render() {
if (!this.state.shouldRender) {
return null;
}

return <WrappedComponent {...this.props} />;
}
}

return DisabledSSRComponent;
}

export default withDisabledSSR;
16 changes: 16 additions & 0 deletions source/hocs/withDisabledSSR/index.spec.js
@@ -0,0 +1,16 @@
import { mount } from 'enzyme/build/index';
import React from 'react';

import withDisabledSSR from './index';

const TestComponent = () => (<div> ...spinner </div>);
const ComponentWithoutSSR = withDisabledSSR(TestComponent);


test('Component without SSR', () => {
const component = mount(
<ComponentWithoutSSR />,
);

expect(component).toMatchSnapshot();
});