What will be shown after clicking the button twice?
medium
A. 2
B. 0
C. 1
D. Error: count is undefined
Solution
Step 1: Understand state and context flow
The Counter component holds count state starting at 0 and provides it via context to Display.
Step 2: Trace button clicks updating count
Each click increases count by 1. After two clicks, count becomes 2, which Display shows.
Final Answer:
2 -> Option A
Quick Check:
2 clicks increase count to 2 = B [OK]
Hint: Count increments by 1 per click, so 2 clicks = 2 [OK]
Common Mistakes:
Thinking context does not update on state change
Assuming count resets on each render
Confusing initial state with updated value
4. What is the main issue with this Next.js code snippet?
import dynamic from 'next/dynamic';
const Widget = dynamic(import('./Widget'));
export default function Page() {
return ;
}
medium
A. Dynamic import should be synchronous.
B. Widget component is not exported as default.
C. Missing arrow function inside dynamic import call.
D. Page component should be class-based.
Solution
Step 1: Check dynamic import syntax
Next.js dynamic() requires a function returning import(), like dynamic(() => import('./Widget')).
Step 2: Identify error in code
The code passes import('./Widget') directly without wrapping in a function, causing an error.
Final Answer:
Missing arrow function inside dynamic import call. -> Option C
Quick Check:
dynamic() needs a function returning import() = D [OK]
Hint: dynamic() must wrap import() in a function () => import() [OK]
Common Mistakes:
Passing import() directly to dynamic()
Thinking component type matters here
Believing dynamic imports are synchronous
5. You want to optimize a complex Next.js UI with many nested components and shared state. Which advanced pattern combination best helps improve performance and code clarity?
hard
A. Load all components statically and use global variables for state.
B. Convert all components to class components and avoid hooks.
C. Use only useState in each component without context or dynamic imports.
D. Use React Context for shared state, dynamic imports for lazy loading, and memoization with useMemo/useCallback.
Solution
Step 1: Identify patterns for shared state and performance
React Context shares state across components; dynamic imports load parts lazily; memoization avoids unnecessary re-renders.
Step 2: Evaluate options for best practice
Use React Context for shared state, dynamic imports for lazy loading, and memoization with useMemo/useCallback. combines these patterns correctly to handle complex UI efficiently and clearly.
Final Answer:
Use React Context for shared state, dynamic imports for lazy loading, and memoization with useMemo/useCallback. -> Option D
Quick Check:
Best combo for complex UI = C [OK]
Hint: Combine context, dynamic imports, and memoization for complex UIs [OK]
Common Mistakes:
Avoiding hooks or context in modern Next.js
Loading all components upfront hurting performance
Using global variables instead of React state
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.