Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
312cf235
Commit
312cf235
authored
Apr 27, 2017
by
Arunoda Susiripala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add docs.
parent
686dd4c4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
0 deletions
+91
-0
readme.md
readme.md
+91
-0
No files found.
readme.md
View file @
312cf235
...
...
@@ -29,6 +29,7 @@ Next.js is a minimalistic framework for server-rendered React applications.
-
[
With `<Link>`
](
#with-link-1
)
-
[
Imperatively
](
#imperatively-1
)
-
[
Custom server and routing
](
#custom-server-and-routing
)
-
[
Dynamic Imports
](
#dynamic-imports
)
-
[
Custom `<Document>`
](
#custom-document
)
-
[
Custom error handling
](
#custom-error-handling
)
-
[
Custom configuration
](
#custom-configuration
)
...
...
@@ -569,6 +570,96 @@ Supported options:
Then, change your
`start`
script to
`NODE_ENV=production node server.js`
.
### Dynamic Import
<p><details>
<summary><b>
Examples
</b></summary>
<ul>
<li><a
href=
"./examples/with-dynamic-import"
>
With Dynamic Import
</a></li>
</ul>
</details></p>
Next.js supports TC39
[
dynamic import proposal
](
https://github.com/tc39/proposal-dynamic-import
)
for JavaScript.
With that, you could import JavaScript modules (inc. React Components) dynamically and work with them.
You can think dynamic imports as another way to split your code into manageable chunks.
Since Next.js supports dynamic imports with SSR, you could do amazing things with it.
Here are a few ways to use dynamic imports.
#### 1. Basic Usage (Also does SSR)
```
js
import
dynamic
from
'next/dynamic'
const
DynamicComponent
=
dynamic
(
import
(
'../components/hello'
))
export
default
()
=>
(
<
div
>
<
Header
/>
<
DynamicComponent
/>
<
p
>
HOME
PAGE
is
here
!<
/p
>
<
/div
>
)
```
#### 2. With Custom Loading Component
```
js
import
dynamic
from
'next/dynamic'
const
DynamicComponentWithCustomLoading
=
dynamic
(
import
(
'../components/hello2'
),
{
loading
:
()
=>
(
<
p
>
...
<
/p>
)
}
)
export
default
()
=>
(
<
div
>
<
Header
/>
<
DynamicComponentWithCustomLoading
/>
<
p
>
HOME
PAGE
is
here
!<
/p
>
<
/div
>
)
```
#### 3. With No SSR
```
js
import
dynamic
from
'next/dynamic'
const
DynamicComponentWithNoSSR
=
dynamic
(
import
(
'../components/hello3'
),
{
ssr
:
false
}
)
export
default
()
=>
(
<
div
>
<
Header
/>
<
DynamicComponentWithNoSSR
/>
<
p
>
HOME
PAGE
is
here
!<
/p
>
<
/div
>
)
```
#### 4. With [async-reactor](https://github.com/xtuc/async-reactor)
> SSR support is not available here
```
js
import
{
asyncReactor
}
from
'async-reactor'
const
DynamicComponentWithAsyncReactor
=
asyncReactor
(
async
()
=>
{
const
Hello4
=
await
import
(
'../components/hello4'
)
return
(
<
Hello4
/>
)
})
export
default
()
=>
(
<
div
>
<
Header
/>
<
DynamicComponentWithAsyncReactor
/>
<
p
>
HOME
PAGE
is
here
!<
/p
>
<
/div
>
)
```
### Custom `<Document>`
<p><details>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment