-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca4da5b
commit ff433db
Showing
5 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 /> | ||
``` | ||
|
||
|
19 changes: 19 additions & 0 deletions
19
source/hocs/withDisabledSSR/__snapshots__/index.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Default Spinner with timeout 1`] = ` | ||
<DisabledSSRComponent> | ||
<TestComponent> | ||
<div> | ||
...spinner | ||
</div> | ||
</TestComponent> | ||
</DisabledSSRComponent> | ||
`; | ||
|
||
exports[`Default Spinner with timeout 2 1`] = ` | ||
<div> | ||
...spinner | ||
</div> | ||
`; | ||
|
||
exports[`Default Spinner with timeout 3 1`] = `<TestComponent />`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { mount, shallow } from 'enzyme/build/index'; | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
|
||
import withDisabledSSR from './index'; | ||
|
||
const TestComponent = () => (<div> ...spinner </div>); | ||
const ComponentWithoutSSR = withDisabledSSR(TestComponent); | ||
|
||
|
||
test('Default Spinner with timeout', () => { | ||
const component = mount( | ||
<ComponentWithoutSSR />, | ||
); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
test('Default Spinner with timeout 2', () => { | ||
const component = renderer.create( | ||
<ComponentWithoutSSR />, | ||
); | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
test('Default Spinner with timeout 3', () => { | ||
const component = shallow( | ||
<ComponentWithoutSSR />, | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); |