NextJS Flashcards
What is Next.js?
A React framework that …
- handles the tooling and configuration needed for React,
- provides additional structure, features and optimizations for your application
What are 5 differences between React and Next.js?
- Next.js has its own compiler
- Fast Refresh comes pre-configured with Next.js
- JS and CSS files are automatically minified in Next.js
- Next.js has built-in support for code-splitting
- Pages in Next.js can be rendered client-side, server-side or with static site generation
What enables routing in Next.js?
Files added to the ‘pages’ folder will automatically be rendered with the matching url.
What element should be used for internal links?
the Link element
———————————————————————————————-
import Link from ‘next/link’;
Example
What element should be used for external links?
The anchor element (<a></a>)
How/where should attributes like ‘className’ be added to links?
Inside the anchor tag, which is wrapped inside Next’ Link element
———————————————————————————————-
import Link from ‘next/link’;
<a>link</a>
How can metadata such as be modified?
By importing and using Next’ element
How can the element be customized in Next.js?
By creating a ‘_document.js’ page inside the ‘pages’ folder (/pages/_document.js)
What is the advantage of the Next.js element vs the HTML element?
It optimizes when additional scripts are fetched and executed.
What additional properties does the element have?
- strategy - controls when the third-party script should load (e.g. ‘lazyOnload’)
- onLoad - runs javaScript code right after the script has finished loading
What styling methods does ext.js have built-in support for?
- CSS modules
- Sass
- PostCSS libraries like Tailwind Css
- CSS-in-JS libraries like styled-jsx
How can global styles be loaded?
By importing the styles into the ‘pages/_app.js’ file (cannot be imported in other files).
What function is used for static generation with data?
getStaticProps()
———————————————————————————————-
export async function getStaticProps() {
// get external data const data = ...
// return props to pass to the component return { props: ... }
}