Skip to content

Commit 61bd3aa

Browse files
authored
SSR compatibility (#79)
* SSR compatibility, solve #78 * Update name prop
1 parent f36b10d commit 61bd3aa

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,17 @@ const MyLoader = () => (
5454

5555
## Options
5656

57-
| Name | Type | Default | Description |
58-
| ------------------- | -------- | --------------- | --------------------------- |
59-
| speed | _Number_ | `2` | Animation speed |
60-
| width | _Number_ | `400` | **viewBox** width of SVG |
61-
| height | _Number_ | `130` | **viewBox** height of SVG |
62-
| style | _Object_ | `null` | Ex: `{ marginTop: '50px' }` |
63-
| primaryColor | _String_ | `#f3f3f3` | Background the SVG |
64-
| secondaryColor | _String_ | `#ecebeb` | Animation color |
65-
| preserveAspectRatio | _String_ | `xMidYMid meet` | Aspect ratio option of SVG |
66-
| className | _String_ | '' | Classname in the <svg /> |
57+
| Name | Type | Default | Description |
58+
| ------------------- | -------- | ---------------- | ------------------------------------------------------------ |
59+
| speed | _Number_ | `2` | Animation speed |
60+
| width | _Number_ | `400` | **viewBox** width of SVG |
61+
| height | _Number_ | `130` | **viewBox** height of SVG |
62+
| style | _Object_ | `null` | Ex: `{ marginTop: '50px' }` |
63+
| primaryColor | _String_ | `#f3f3f3` | Background the SVG |
64+
| secondaryColor | _String_ | `#ecebeb` | Animation color |
65+
| preserveAspectRatio | _String_ | `xMidYMid meet` | Aspect ratio option of SVG |
66+
| className | _String_ | '' | Classname in the <svg /> |
67+
| uniquekey | _String_ | random unique id | **Use the same key value, it'll solve some problems to SSR** |
6768

6869
### Examples
6970

src/Wrap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export type WrapProps = {
99
} & ContentLoaderProps
1010

1111
const Wrap = (props: WrapProps): React.Element<*> => {
12-
const idClip = uid()
13-
const idGradient = uid()
12+
const idClip = `${props.uniquekey}-idClip` || uid()
13+
const idGradient = `${props.uniquekey}-idGradient` || uid()
1414

1515
return (
1616
<svg

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type Props = {
1919
secondaryColor: string,
2020
preserveAspectRatio: string,
2121
className: string,
22+
uniquekey: string,
2223
}
2324

2425
const defaultProps = {

stories/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ storiesOf('ContentLoader', module)
6363
<ContentLoader width={400} height={150} />
6464
</Container>
6565
))
66+
.add('unique-key: for SSR', () => (
67+
<Container>
68+
<ContentLoader uniquekey="unique-key" />
69+
</Container>
70+
))

0 commit comments

Comments
 (0)