diff --git a/examples/with-dynamic-import/components/hello3.js b/examples/with-dynamic-import/components/hello3.js new file mode 100644 index 00000000..809e3ddb --- /dev/null +++ b/examples/with-dynamic-import/components/hello3.js @@ -0,0 +1,3 @@ +export default () => ( +

Hello World 3 (imported dynamiclly)

+) diff --git a/examples/with-dynamic-import/pages/index.js b/examples/with-dynamic-import/pages/index.js index fa768c75..bf8dec9a 100644 --- a/examples/with-dynamic-import/pages/index.js +++ b/examples/with-dynamic-import/pages/index.js @@ -10,12 +10,17 @@ const DynamicComponentWithCustomLoading = dynamic( loading: () => (

...

) } ) +const DynamicComponentWithNoSSR = dynamic( + import('../components/hello3'), + { ssr: false } +) export default () => (
+

HOME PAGE is here!

diff --git a/lib/dynamic.js b/lib/dynamic.js index 9197b5d8..9c80c32c 100644 --- a/lib/dynamic.js +++ b/lib/dynamic.js @@ -6,10 +6,16 @@ export default function dynamicComponent (promise, options = {}) { return class Comp extends React.Component { constructor (...args) { super(...args) + this.LoadingComponent = options.loading ? options.loading : () => (

loading...

) + this.ssr = options.ssr === false ? options.ssr : true + this.state = { AsyncComponent: null } this.isServer = typeof window === 'undefined' - this.loadComponent() + + if (this.ssr) { + this.loadComponent() + } } loadComponent () { @@ -27,6 +33,9 @@ export default function dynamicComponent (promise, options = {}) { componentDidMount () { this.mounted = true + if (!this.ssr) { + this.loadComponent() + } } render () {