Assess your knowledge of ReactJS basics with these key questions covering core concepts like components, state, hooks, and routing. Perfect for anyone starting out in modern frontend development.
What is React mainly used for in frontend development?
Explanation: React is primarily used for creating user interfaces by composing them from reusable components. Managing databases and server-side scripting are handled by other technologies. Writing backend APIs is also not the main focus of React.
What is JSX in the context of React?
Explanation: JSX allows developers to write HTML-like code within JavaScript, making UI code more readable and intuitive. It is not a CSS preprocessor or API standard, nor is it used for databases.
Which React hook is commonly used to manage state within a functional component?
Explanation: useState() is the standard hook for introducing and managing state in functional components. useRef() is for referencing DOM nodes, useMemo() optimizes performance, and useReducer() is for complex state logic.
Which hook is used in React to handle side effects such as data fetching or timers?
Explanation: useEffect() is designed for handling side effects in React components. useSelector() relates to state management libraries, useCallback() optimizes functions, and useLayoutEffect() is for syncing layout side effects.
What is a component in React?
Explanation: Components in React encapsulate and reuse UI pieces, improving code organization. They are not files, styling methods, or external libraries.
In React, what are props?
Explanation: Props allow parent components to send data to their children, enabling dynamic and reusable components. They are not scripts, state methods, or CSS rules.
What is the Virtual DOM in React?
Explanation: The Virtual DOM is a technique to efficiently update the UI by comparing changes before updating the real DOM. It is not a server, code-writing tool, or browser extension.
How can you conditionally render UI elements in React?
Explanation: Conditional rendering in React is typically done with logical (&&) or ternary (? :) operators in JSX. Modifying HTML directly or using CSS and database triggers do not control React component rendering.
Which hook allows a React component to access context values provided by a provider?
Explanation: useContext() is the React hook for subscribing to context values. useEffect() is for side effects, useReducer() handles state logic, and useParams() is associated with routing.
What is React Router primarily used for in a React application?
Explanation: React Router enables single-page applications to have navigation and route different views. It does not handle styling, UI animation, or pure performance optimizations.