nextjs mcqs preparation
nextjs mcqs preparation
● GitHub: https://github.com/kanwalhafsa
● LinkedIn: https://linkedin.com/in/hafsa-kanwal-2945442b7
○ A) 8000
○ B) 5000
○ C) 3000
○ D) 8080
○ Answer: C
6. In Next.js, how are routes created?
○ A) By defining routes in next.config.js
○ B) By creating files inside the pages directory
○ C) By using a router object in React
○ D) By writing routes in server.js
○ Answer: B
7. What is the correct syntax for dynamic routes in Next.js?
○ A) [id].js
○ B) {id}.js
○ C) <id>.js
○ D) $id.js
○ Answer: A
8. How do you navigate programmatically in Next.js?
○ A) Using window.location
○ B) Using Router.push()
○ C) Using Link component only
○ D) Using router.push() from useRouter
○ Answer: D
9. What is the purpose of getStaticPaths in Next.js?
○ A) To fetch data during server-side rendering
○ B) To generate paths for dynamic routes at build time
○ C) To manage API endpoints
○ D) To configure custom middleware
○ Answer: B
10.Which feature of Next.js ensures client-side navigation?
○ A) next/router
○ B) window.history
○ C) app-router
○ D) next-history
○ Answer: A
11. What directory is used for API routes in Next.js?
○ A) /api
○ B) /pages/api
○ C) /routes/api
○ D) /server/api
3
○ Answer: B
12.How can you define a POST API route in Next.js?
○ A) Using app.js
○ B) Creating a file in pages/api and handling POST in the handler
○ C) Using next.api
○ D) Defining POST in next.config.js
○ Answer: B
13.What is the default export in an API route file?
○ A) An object
○ B) A string
○ C) A function handling the request and response
○ D) A React component
○ Answer: C
14.How do you return JSON data in an API route?
○ A) res.json(data)
○ B) res.write(data)
○ C) res.data(data)
○ D) res.sendJSON(data)
○ Answer: A
15.What HTTP methods can be handled in a Next.js API route?
○ A) Only GET and POST
○ B) All standard HTTP methods (e.g., GET, POST, PUT, DELETE)
○ C) Only PUT and DELETE
○ D) Only custom methods
○ Answer: B
16.What does the next/image component optimize?
○ A) Text content
○ B) Images for faster loading and responsiveness
○ C) CSS performance
○ D) Database queries
○ Answer: B
17.How do you preload a font in Next.js?
○ A) Use the next/font package
○ B) Add a <link> tag in _document.js
○ C) Both A and B
○ D) Use the font tag
○ Answer: C
18.How can you configure redirects in Next.js?
○ A) By using next/redirect
4
○ Answer: A
25.What is the purpose of GROQ in Sanity?
○ A) Managing CSS files
○ B) Querying content from the Sanity backend
○ C) Writing API endpoints
○ D) Managing React components
○ Answer: B
30. How do you filter records with a specific field value in GROQ?
● A) *[field == "value"]
● B) FETCH records WHERE field = value
● C) GET field IS value
6
● D) FILTER(field=value)
● Answer: A
31. Which GROQ keyword is used to limit the number of results returned?
● A) LIMIT
● B) max()
● C) count
● D) [_limit == n]
● Answer: A
● A) {field1, field2}
● B) SELECT field1, field2
● C) fields: [field1, field2]
● D) field1, field2
● Answer: A
34. Which method fetches dynamic GROQ queries using Sanity’s JavaScript client?
● A) client.fetch(groqQuery)
● B) sanity.dynamicQuery()
● C) query.fetch()
● D) fetchDynamic()
● Answer: A
36. Which hook is recommended to fetch dynamic data in a server-side rendered page?
● A) getServerSideProps
7
● B) useEffect
● C) useQuery
● D) getStaticProps
● Answer: A
Answer: D
Answer: A
40. Which lifecycle method is used to fetch data on the server side in Next.js?
A. componentDidMount
B. getServerSideProps
C. useEffect
D. componentWillUnmount
Answer: B
Answer: B
Answer: A
Answer: A
Answer: D
A. File-based routing
B. API-based routing
C. Query string routing
D. Hash-based routing
Answer: A
Answer: C
47. Which hook is commonly used in Next.js to fetch data on the client side?
A. useEffect
B. useFetch
C. useServerSideProps
D. useData
Answer: A
Answer: B
Answer: A
Answer: C
51. Which tool does Sanity use for managing content and media?
A. Sanity Studio
B. Sanity Cloud
10
C. Sanity CMS
D. Sanity Media Manager
Answer: A
Answer: A
Answer: B
Answer: B
A. m-{size}
B. mt-{size}
C. margin-{size}
D. margin-top-{size}
Answer: A
Answer: B
A. p-{size}
B. padding-{size}
C. pt-{size}
D. space-{size}
Answer: A
A. A CSS framework
B. A UI component library built for React
C. A JavaScript tool for creating animations
D. A content management system
Answer: B
Answer: A
Answer: B