-
What is the primary command used to initialize a new Next.js project?
- npm create-next-app@latest
- npx next-init
- npm install next
- npx create-next-js
Correct Answer: npm create-next-app@latest
Explanation: The document specifies 'npx create-next-app@latest' as the command to install Next.js.
-
Which two packages are essential for adding Redux to a Next.js project according to the guide?
- redux and react
- redux-thunk and redux
- react-redux and @reduxjs/toolkit
- redux-toolkit and next-redux
Correct Answer: react-redux and @reduxjs/toolkit
Explanation: The guide instructs to install 'react-redux' and '@reduxjs/toolkit'.
-
Where should the 'redux' folder be ideally created in a Next.js app?
- In the root directory
- In the 'public' folder
- Within the 'src' folder
- Inside the 'components' folder
Correct Answer: Within the 'src' folder
Explanation: Step #3 instructs to create the 'redux' folder within the 'src' folder.
-
Which file is used to define the initial state and reducers in the guide?
- store.ts
- counterSlice.ts
- StoreProvider.tsx
- layout.tsx
Correct Answer: counterSlice.ts
Explanation: Step #4 involves creating the 'counterSlice.ts' file to define slices, initial state, and reducers.
-
What function is imported from '@reduxjs/toolkit' to set up the store?
- createStore
- configureStore
- combineReducers
- createSlice
Correct Answer: configureStore
Explanation: The document shows 'configureStore' being imported from '@reduxjs/toolkit' in 'store.ts'.
-
Which directive is required at the top of a file to use Redux hooks in the App Router?
- 'use server'
- 'use client'
- 'use strict'
- 'use redux'
Correct Answer: 'use client'
Explanation: The guide emphasizes that 'use client' is necessary to access state and dispatch actions.
-
What is the primary purpose of the 'StoreProvider.tsx' file?
- To define the initial Redux state
- To wrap the application with the Redux Provider
- To store API configurations
- To create action creators
Correct Answer: To wrap the application with the Redux Provider
Explanation: The 'StoreProvider' uses the Redux 'Provider' component to pass the store to the application children.
-
In which file do you wrap the 'children' prop with the 'StoreProvider'?
- page.tsx
- store.ts
- layout.tsx
- app.tsx
Correct Answer: layout.tsx
Explanation: Step #7 states that you must go to 'src/app/layout.tsx' and wrap the 'children' prop with the 'StoreProvider'.
-
Which Redux hook is used for accessing the store state?
- useDispatch
- useSelector
- useStore
- useState
Correct Answer: useSelector
Explanation: The guide uses 'useSelector' to extract the count value from the Redux state.
-
Which Redux hook is used to trigger action creators?
- useSelector
- useAction
- useDispatch
- useReducer
Correct Answer: useDispatch
Explanation: The 'useDispatch' hook is required to call action creators from the slice.
-
How do you access the count from the state in the counter example?
- state.count
- state.counter.count
- state.value
- state.counter
Correct Answer: state.counter.count
Explanation: The code uses 'state.counter.count', reflecting the structure defined in the 'store.ts' reducer object.
-
What does 'counterSlice.actions' provide?
- The store instance
- The action creators
- The root reducer
- The initial state
Correct Answer: The action creators
Explanation: 'counterSlice.actions' automatically generates action creators for the reducers defined in the slice.
-
Why is 'page.tsx' referred to as a 'server component' in the guide?
- Because it must run on the server to fetch data
- Because Next.js defaults to server components in the App Router
- Because it is in the root directory
- Because it cannot contain CSS
Correct Answer: Because Next.js defaults to server components in the App Router
Explanation: In Next.js App Router, components are Server Components by default unless marked with 'use client'.
-
In the 'Counter' component, how are actions triggered?
- By calling the action creator directly
- By dispatching the action creator
- By using a reducer function
- By updating the state directly
Correct Answer: By dispatching the action creator
Explanation: You must dispatch the result of the action creator (e.g., dispatch(counterActions.increment())) to update state.
-
Where is the 'Counter' component imported and rendered?
- layout.tsx
- StoreProvider.tsx
- page.tsx
- store.ts
Correct Answer: page.tsx
Explanation: Step #9 describes importing the 'Counter' component into the 'page.tsx' file.
-
What is the correct syntax for creating a slice with 'createSlice'?
- name, initialState, reducers
- reducer, state
- slice, store
- actions, dispatch
Correct Answer: name, initialState, reducers
Explanation: The 'createSlice' function accepts an object containing 'name', 'initialState', and 'reducers'.
-
Is it possible to import a client component into a server component?
- No, it breaks the build
- Yes, as long as it has 'use client' at the top
- Only if it is a library component
- Yes, but it won't be reactive
Correct Answer: Yes, as long as it has 'use client' at the top
Explanation: The guide demonstrates importing the client component 'Counter.tsx' into the server component 'page.tsx'.
-
In the counter slice, what does 'state.count++' do?
- Throws an error because state is immutable
- Uses Immer internally to safely update state
- Creates a new object for the state
- Returns a new count value
Correct Answer: Uses Immer internally to safely update state
Explanation: Redux Toolkit uses the Immer library, allowing you to write 'mutating' logic that is safely handled behind the scenes.
-
What is the role of the 'store' property in the Provider component?
- It acts as the configuration object
- It connects the React app to the Redux store instance
- It is the main entry point for the Redux slices
- It defines the middleware
Correct Answer: It connects the React app to the Redux store instance
Explanation: The 'Provider' component takes the 'store' as a prop to make it available to all nested components.
-
What file structure was suggested for the slices?
- root/redux/slices/counterSlice.ts
- root/slices/counterSlice.ts
- root/src/redux/counterSlice.ts
- root/src/redux/slices/counterSlice.ts
Correct Answer: root/src/redux/slices/counterSlice.ts
Explanation: The image on Step #4 clearly shows the path as src/redux/slices/counterSlice.ts.