React NextJS Concepts Full
React NextJS Concepts Full
JSX
JSX allows you to write HTML-like syntax in JavaScript files, which makes the structure of
Component
A component is a reusable building block of a UI in React. It can be a class or a function that returns
JSX.
Props
Props (short for properties) are read-only inputs passed from a parent to a child component. They're
State
State is a built-in object that stores data or UI status that may change over the component's
lifecycle.
useState()
A React Hook that adds state to functional components. It returns an array with the current state and
a setter function.
useEffect()
This hook lets you run side effects like fetching data or modifying the DOM. It replaces lifecycle
useRef()
useRef returns a mutable ref object used to access DOM elements or persist values between
useContext()
Provides a way to pass data through the component tree without having to pass props down
React.memo()
Controlled Component
An input element whose value is controlled by React state. This makes React the source of truth.
Uncontrolled Component
An input element that maintains its own internal state using the DOM, accessed with refs.
Keys in Lists
Keys help React identify which items have changed, are added, or removed when rendering lists.
Virtual DOM
A lightweight JavaScript object representing the actual DOM. React compares versions and updates
Reconciliation
The process React uses to compare the new virtual DOM with the previous one and update the real
DOM efficiently.
Fragment
A way to return multiple elements from a component without adding extra nodes to the DOM.
Conditional Rendering
React Router
A standard library for routing in React. It enables navigation between views without full-page
reloads.
Lifting State Up
Moving shared state to a common ancestor component so that multiple children can access and
modify it.
A function that takes a component and returns a new enhanced component, used for code reuse.
Context API
A way to manage global state across a React app, avoiding prop drilling.
Next.js Concepts - Full Definitions
File-based Routing
In Next.js, each file inside the 'pages/' directory automatically becomes a route.
Dynamic Routing
Using bracket syntax like [id].js in 'pages/' to handle dynamic routes like /post/1.
useRouter()
A hook from next/router that allows access to router object including route parameters.
getStaticProps()
Fetch data at build time and use it to pre-render a page for faster performance.
getServerSideProps()
Fetch data on every request, useful for content that changes often or depends on auth.
getStaticPaths()
Defines the dynamic routes that need to be statically generated at build time.
API Routes
Create REST API endpoints directly in Next.js inside the pages/api/ folder.
Image Optimization
The next/image component provides automatic image resizing, lazy loading, and more.
Head Component
Allows modifying elements in the <head> of the page like title, meta tags, etc.
Link Component
Place static files in the /public directory and access them directly via URL paths.
Pages are pre-rendered to HTML at build time and served from cache.
Fallback Rendering
Deployment
Next.js apps are easily deployable on Vercel, which supports static and serverless functions.