Server state is data fetched and stored on the server. It is sent to the client during rendering, often used for initial page load or server-side rendering.
Click to reveal answer
beginner
What is client state in Next.js?
Client state is data managed inside the browser after the page loads. It changes based on user actions without needing to reload the page from the server.
Click to reveal answer
intermediate
Why do we separate server state and client state?
Separating helps manage data efficiently. Server state handles data from APIs or databases, while client state manages UI changes and user input locally.
Click to reveal answer
intermediate
How does Next.js fetch server state?
Next.js uses functions like getServerSideProps or getStaticProps to fetch server state before rendering pages.
Click to reveal answer
beginner
Give an example of client state in a Next.js app.
Client state example: a toggle button that changes color when clicked, managed with React's useState hook inside the browser.
Click to reveal answer
Which Next.js function is used to fetch server state at request time?
AgetServerSideProps
BuseState
CuseEffect
DgetStaticPaths
✗ Incorrect
getServerSideProps runs on the server at each request to fetch fresh server state.
Client state is usually managed with which React hook?
AgetServerSideProps
BuseEffect
CuseState
DgetStaticProps
✗ Incorrect
useState manages client state inside React components.
Which of these is NOT true about server state?
AIt is fetched on the server.
BIt can be sent as props to components.
CIt can come from APIs or databases.
DIt updates automatically on user clicks without reload.
✗ Incorrect
Server state does not update automatically on user clicks without reload; that is client state behavior.
Why might you use client state in a Next.js app?
ATo handle user input and UI changes instantly.
BTo fetch data from a database.
CTo generate static pages.
DTo run server-side code.
✗ Incorrect
Client state handles UI changes and user input instantly without server reload.
Which statement best describes server state?
AData stored only in the browser.
BData fetched and prepared on the server before sending to client.
CData that changes only on user clicks.
DData managed by React hooks like useState.
✗ Incorrect
Server state is fetched and prepared on the server before sending to the client.
Explain the difference between server state and client state in Next.js.
Think about where the data lives and when it updates.
You got /4 concepts.
Describe how Next.js handles server state fetching and how client state is managed.
Consider the data flow from server to client and inside the client.
You got /4 concepts.
Practice
(1/5)
1. Which of the following best describes server state in Next.js?
easy
A. UI component states like button clicks or form inputs.
B. Temporary data stored only in the browser memory.
C. CSS styles applied to components dynamically.
D. Data fetched from APIs or databases and shared across users.
Solution
Step 1: Understand server state meaning
Server state is data that comes from the server, such as API responses or database queries, and is shared among users.
Step 2: Compare with client state
Client state is local to the browser and changes instantly with user actions, unlike server state.
Final Answer:
Data fetched from APIs or databases and shared across users. -> Option D
Quick Check:
Server state = shared API data [OK]
Hint: Server state = shared data from backend, not local UI [OK]
Common Mistakes:
Confusing server state with client UI state
Thinking server state is local to one user
Mixing server state with CSS or styling
2. Which syntax correctly uses React's useState hook for client state in Next.js?
easy
A. const [count, setCount] = useState(0)
B. const [data, setData] = useState(fetch('/api/data'))
C. const data = await fetch('/api/data')
D. const count = useState(0)
Solution
Step 1: Identify correct useState syntax
useState returns an array with current state and a setter function, so destructuring with [state, setState] is correct.
Step 2: Check each option
const [count, setCount] = useState(0) correctly uses const [count, setCount] = useState(0). const [data, setData] = useState(fetch('/api/data')) wrongly calls fetch inside useState. const data = await fetch('/api/data') is an async fetch, not useState. const count = useState(0) misses destructuring.
React's useEffect callback cannot be async directly; it should call an async function inside.
Step 2: Identify correct fix
Wrap the async fetch logic inside a separate async function inside useEffect, then call it.
Final Answer:
useEffect callback cannot be async directly -> Option A
Quick Check:
Async function inside useEffect, not async callback [OK]
Hint: useEffect callback must be sync; call async function inside [OK]
Common Mistakes:
Making useEffect callback async directly
Not handling initial undefined state safely
Assuming data.message exists before fetch
5. You want to build a Next.js page that shows a list of products fetched from the server and allows users to filter them locally without refetching. Which approach correctly separates server state and client state?
hard
A. Store products in client state only and fetch on every filter change.
B. Fetch products inside useEffect and store in server state for filtering.
C. Fetch products with getServerSideProps and store in client state with useState for filtering.
D. Fetch products with getStaticProps and filter on server on every user input.
Solution
Step 1: Understand server state fetching
Using getServerSideProps fetches data on the server before rendering, providing server state.
Step 2: Manage client state for filtering
Storing the fetched products in useState allows local filtering without refetching, which is client state.
Final Answer:
Fetch products with getServerSideProps and store in client state with useState for filtering. -> Option C
Quick Check:
Server fetch + client filter state = Fetch products with getServerSideProps and store in client state with useState for filtering. [OK]
Hint: Fetch server data once, filter locally with client state [OK]
Common Mistakes:
Fetching data on every filter change
Filtering on server for every user input
Mixing server and client state responsibilities
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.