React Hooks Building React App 2 — Questions and Answers
Question 1: Which command from Vite scaffolds a new React app with hooks support?
- npm create vite@latest my-app -- --template react (Correct answer)
- npm install react-app
- npx build react my-app
- npm run react new
Correct answer: npm create vite@latest my-app -- --template react
Vite's create command with the react template scaffolds a modern React project.
Question 2: In a freshly created React app, where is the root component typically mounted?
- In index.css
- In main.jsx / index.js using createRoot (Correct answer)
- In package.json
- In vite.config.js
Correct answer: In main.jsx / index.js using createRoot
The entry file calls createRoot and renders the App component into the DOM root node.
Question 3: What hook would you add to App.jsx to store a counter value?
- useEffect
- useState (Correct answer)
- useRef
- useContext
Correct answer: useState
useState manages local component state such as a counter.
Question 4: Which file usually contains the React component tree's top-level component?
- App.jsx (Correct answer)
- robots.txt
- tsconfig.json
- README.md
Correct answer: App.jsx
App.jsx (or App.tsx) holds the top-level application component.
Question 5: After editing a component, how does Vite reflect changes in the browser without a full reload?
- Manual rebuild
- Hot Module Replacement (HMR) (Correct answer)
- Server restart only
- Browser cache clear
Correct answer: Hot Module Replacement (HMR)
Vite uses HMR to swap updated modules while preserving app state.
Question 6: Which dependency must be installed for JSX to work in a React app?
- react and react-dom (Correct answer)
- express
- lodash
- axios
Correct answer: react and react-dom
react provides the core library and react-dom renders JSX to the browser DOM.
Question 7: What is the purpose of the public folder in a Vite React app?
- Stores compiled bundles
- Holds static assets served as-is (Correct answer)
- Contains node_modules
- Defines routes
Correct answer: Holds static assets served as-is
Files in public are served at the root path without processing.
Which command from Vite scaffolds a new React app with hooks support?