Skip to content

Commit b5a03a3

Browse files
committed
Implement ssr=false support.
1 parent f2bfcd0 commit b5a03a3

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default () => (
2+
<p>Hello World 3 (imported dynamiclly) </p>
3+
)

examples/with-dynamic-import/pages/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ const DynamicComponentWithCustomLoading = dynamic(
1010
loading: () => (<p>...</p>)
1111
}
1212
)
13+
const DynamicComponentWithNoSSR = dynamic(
14+
import('../components/hello3'),
15+
{ ssr: false }
16+
)
1317

1418
export default () => (
1519
<div>
1620
<Header />
1721
<DynamicComponent />
1822
<DynamicComponentWithCustomLoading />
23+
<DynamicComponentWithNoSSR />
1924
<p>HOME PAGE is here!</p>
2025
<Counter />
2126
</div>

lib/dynamic.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ export default function dynamicComponent (promise, options = {}) {
66
return class Comp extends React.Component {
77
constructor (...args) {
88
super(...args)
9+
910
this.LoadingComponent = options.loading ? options.loading : () => (<p>loading...</p>)
11+
this.ssr = options.ssr === false ? options.ssr : true
12+
1013
this.state = { AsyncComponent: null }
1114
this.isServer = typeof window === 'undefined'
12-
this.loadComponent()
15+
16+
if (this.ssr) {
17+
this.loadComponent()
18+
}
1319
}
1420

1521
loadComponent () {
@@ -27,6 +33,9 @@ export default function dynamicComponent (promise, options = {}) {
2733

2834
componentDidMount () {
2935
this.mounted = true
36+
if (!this.ssr) {
37+
this.loadComponent()
38+
}
3039
}
3140

3241
render () {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy