Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Next.js Quick Start Guide

You're reading from   Next.js Quick Start Guide Server-side rendering done right

Arrow left icon
Product type Paperback
Published in Jul 2018
Publisher Packt
ISBN-13 9781788993661
Length 164 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Kirill Konshin Kirill Konshin
Author Profile Icon Kirill Konshin
Kirill Konshin
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Introduction to Server-Side Rendering and Next.js 2. Next.js fundamentals FREE CHAPTER 3. Next.js Configuration 4. Next.js Data Flow 5. Application Life Cycle Handlers and Business Logic 6. Continuous Integration 7. Containers 8. Other Books You May Enjoy

Dynamic Component Loading (aka Lazy Components)

Even though Next.js can split your app into route-based asynchronously loaded chunks, it is always a good idea to split further if it is needed. The less unnecessary code the user loads up front, the better.

The technique is very simple and completely supported by Next.js:

import dynamic from 'next/dynamic';

And then, anywhere on demand, we can do the loading:

import dynamic from 'next/dynamic'

const FooDynamic = dynamic(import('../components/Foo'))

export default class Page extends React.Component {

state = {show: false};

show = () => this.setState({show: true});

render() {
return (
this.state.show ? <FooDynamic/> : <button onClick={this.show}>Show!</button>
);
}

}

Here, the component will not be loaded until it is actually placed on the page (that is, rendered...

You have been reading a chapter from
Next.js Quick Start Guide
Published in: Jul 2018
Publisher: Packt
ISBN-13: 9781788993661
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime