← All React Flashcard Decks

REACT Flashcards

25 cards from real React practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 20 REACT flashcards as text
  1. Which of the following React functions will update the data of a component while remaining within the componentWillMount?

    Answer: setState()

    The `setState()` function is the primary way to update a component's state in React, triggering a re-render. While `componentWillMount` is a legacy lifecycle method called before the component mounts, calling `setState()` within it allows you to update the component's state before the initial render, ensuring the component mounts with the desired data. However, for new code, `constructor` for initial state or `componentDidMount` for data fetching is generally preferred.

  2. What does React not include?

    Answer: All of the above

    React is a library primarily focused on building user interfaces, specifically the 'V' in MVC. It intentionally does not include features like a built-in data layer (leaving that to state management libraries like Redux), its own AJAX capabilities (relying on standard JavaScript APIs like `fetch` or `axios`), or a comprehensive event system beyond synthetic DOM events. This modularity allows developers to choose their preferred tools for these concerns.

  3. Which step should be completed first when configuring Gulp on a developer machine?

    Answer: Define a gulpfile.js

    When setting up Gulp, the first essential step after installing Gulp globally and locally is to create a `gulpfile.js` file in your project's root directory. This file is where you define all your Gulp tasks, specifying what operations Gulp should perform, such as compiling SASS, minifying JavaScript, or running a local server. Without this file, Gulp has no instructions to execute.

  4. Which JavaScript API may be used to delete an item from a Flux store's private storage?

    Answer: Lodash

    Lodash is a popular JavaScript utility library that provides a wide range of helper functions for common programming tasks, including manipulating arrays and objects. While Flux stores manage their own state, Lodash functions like `_.omit` or `_.without` can be used within a store's logic to immutably remove items from its private data structures, making it a useful tool for state management operations within the store.

  5. For type verification in React components, what property name is used?

    Answer: propTypes

    In React, `propTypes` is a special static property used within a component definition to specify the expected data types for the props it receives. This mechanism helps with type checking during development, providing warnings in the console if props don't match the defined types. It's a valuable tool for ensuring component reliability, maintainability, and clear communication of component interfaces.

  6. In the following code segment, select the reason for adding code to the index.js file - S = jQuery= require("jquery");

    Answer: Bootstrap expects 'jQuery to be in a global space

    Many older JavaScript libraries, including Bootstrap, were designed to expect jQuery to be available as a global variable (e.g., `window.jQuery` or `window.$`). The line `S = jQuery = require("jquery");` ensures that jQuery is not only imported but also assigned to these global variables. This satisfies Bootstrap's dependency, allowing it to function correctly in environments where it expects global access to jQuery.

  7. Prepopulate a form in a React form component using which component lifecycle method

    Answer: componentWillMount

    `componentWillMount` (now considered legacy and replaced by `constructor` or `getDerivedStateFromProps` in modern React) was a lifecycle method called just before a component mounts. It was a suitable place to set initial state based on props or other data, making it useful for prepopulating form fields before the component's initial render. For new code, `componentDidMount` for data fetching or `constructor` for initial state is preferred.

  8. What isn't a Browserify advantage?

    Answer: Increases HTTP requests to get JS modules

    Browserify's primary advantage is that it allows developers to use Node.js-style `require()` statements in client-side JavaScript, bundling all dependencies into a single file. This process *reduces* the number of HTTP requests needed to load JavaScript modules, leading to faster loading applications, not increasing them. It streamlines module management for the browser by consolidating multiple files into one.

  9. Choose a programming language that isn't used in the ESLintrc file.

    Answer: C

    The `.eslintrc` file is used to configure ESLint, a popular linter for JavaScript, to enforce coding standards and identify potential issues. These configuration files are typically written in formats like JSON, YAML, or JavaScript itself. C is a low-level compiled programming language and is not used for configuring JavaScript linters, as it operates at a different level of abstraction.

  10. What distinguishes the React Router?

    Answer: D)All of the above

    React Router is a powerful library for declarative routing in React applications, allowing routes to be configured using JSX, which enhances readability and maintainability. It supports a simple nested approach for defining routes, enabling complex UI structures and dynamic navigation. Its focus is on managing the 'View' aspect of an application, providing a robust way to handle navigation and UI changes based on the URL.

  11. Which sentence allows a tag named 'InputComp' to use a React reusable text input component found in the file 'TextlnputComp.jsx'?

    Answer: var InputComp = require(‘../ TextlnputComp.jsx');

    In environments using CommonJS modules (like Node.js or when bundled with tools like Webpack/Browserify), the `require()` function is used to import modules from other files. This statement imports the component exported from `TextlnputComp.jsx` and assigns it to the variable `InputComp`, making it available for use within the current file as a React component.

  12. What is modified when an action is added to edit a component's data?

    Answer: Store.jsx, the component store

    In the Flux architecture, actions describe what happened, but they don't directly modify data. Instead, actions are dispatched to the Dispatcher, which then sends them to relevant Stores. It is the Store's responsibility to listen for specific actions, update its own private state based on those actions, and then emit a change event. Therefore, when an action is added to edit data, the `Store.jsx` file (or the relevant store) is where the data modification logic resides.

  13. The rendering of JSX tiles needs

    Answer: React-DOM

    JSX is a syntax extension that allows you to write HTML-like code within JavaScript, but browsers cannot directly interpret it. React-DOM is the library specifically designed to take your React components, including those defined with JSX, and efficiently render them into the actual browser's Document Object Model (DOM). It acts as the crucial bridge between your React application's virtual representation and what the user sees in the browser.

  14. Which React function will display child components of a given component?

    Answer: render()

    In React class components, the `render()` method is a fundamental and required lifecycle method. Its primary purpose is to return the JSX (or other valid React elements) that describes the user interface for that component, including any child components it contains. When React needs to display or update a component, it calls this method to determine what should be rendered on the screen.

  15. In React, which store function is not used to configure the change listener?

    Answer: None of the above

    This question refers to the Flux architecture, which is a pattern for managing application state. In Flux, stores typically provide methods like `addChangeListener` (or `registerListener`) and `removeChangeListener` (or `deregisterListener`) for components to subscribe to and unsubscribe from state changes. The term 'change' itself is an event or concept, not a store function used to configure listeners; therefore, none of the listed options are incorrect store functions for this purpose.

  16. What distinguishes the virtual DOM?

    Answer: JavaScript objects update faster

    The Virtual DOM is a lightweight, in-memory representation of the actual browser DOM, built using JavaScript objects. Manipulating these JavaScript objects is significantly faster and less resource-intensive than directly interacting with the browser's real DOM. React leverages this speed by first updating the Virtual DOM, then efficiently calculating the minimal changes needed before applying them to the slower, actual DOM.

  17. When added to a component's style, it determines the layout's primary axis, and when using React's flexbox, it determines the layout's primary axis.

    Answer: flexDirection

    `flexDirection` is a core CSS property used in Flexbox layouts to define the main axis along which flex items are arranged. When applied to a component's style in React (especially in React Native or with inline styles), it determines whether children are laid out horizontally (`row`) or vertically (`column`). This property is essential for controlling the direction and flow of elements within a flexible container.

  18. In React, what is a Flux property?

    Answer: Pattern

    Flux is an application architecture or design pattern, not a framework or a library itself. It provides a set of principles for managing application state and data flow in a unidirectional manner, complementing React's component-based UI. While libraries like Redux implement Flux principles, Flux itself is the conceptual pattern that guides how data flows through an application.

  19. Which of the following packages best demonstrates React's utility?

    Answer: React-Router

    React-Router is a widely used library that enables declarative routing in React applications, allowing for the creation of single-page applications with multiple views and navigation. It demonstrates React's utility by extending its capabilities beyond just UI rendering to include complex application structure and user experience. This package is a prime example of how React can be used to build full-featured web applications.

  20. What isn't a part of CommonJS that is used to specify modules?

    Answer: Insert statement

    CommonJS is a module specification primarily used in Node.js environments for organizing JavaScript code into reusable modules. Its core mechanisms involve `require()` for importing modules and `module.exports` (or `exports`) for defining what a module makes available. The concept of an 'insert statement' is not part of the standard CommonJS syntax for module definition or usage.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy