JOBSEEKER?

React Interview Questions

Practice for React interviews by solving TestDome questions. Our interview questions are used by more than 7,000 companies and 450,000 individual test takers.

Jobseekers: Certify Your Knowledge

Take a Certification Test

Companies: Use Our Tests for Screening

Buy a Pack Of Candidates

Need to practice your React skills for an upcoming job interview? Try solving these React interview questions that test knowledge of components, event handling, reference hooks, and other skills. We’ll provide feedback on your answers, and you can use a hint if you get stuck.

These React interview questions are examples of real tasks used by employers to screen job candidates such as React developers, JavaScript developers, front-end developers, and others that need to use the React library and leverage its commonly used programming patterns.

1. Logout Wrapper

Easy  
React Context React Hooks New Public

Consider the following components:

const SecurityContext = React.createContext({ username: "", permissions: [] });

const ControlsComponent = (props) => {
  return (
    <SecurityContext.Provider value={{ username: props.username }}>
      <LogoutWrapper></LogoutWrapper>
    </SecurityContext.Provider>
  );
};

const LogoutWrapper = (props) => {
  var context = React.useContext(SecurityContext);
  
  return (
    <div>
      <p>{context.username}</p>
      <button>Click here to logout</button>
    </div>
  );
};

Select all the correct statements if ControlsComponent is rendered with the username prop equal to "James".

(Select all acceptable answers.)

Solve Question

2. Focusable Input

Easy  
React Effect Hook React Hooks Reference Hook New Public

Finish the FocusableInput component so that the input element automatically receives focus on the first render if the shouldFocus prop is true.

The component should use React Hooks.

Solve Question

3. Toggle Message

Easy  
React Conditional Rendering Event Handling Managing State Public

The Message component contains an anchor element and a paragraph below the anchor. Rendering of the paragraph should be toggled by clicking on the anchor element using the following logic:

  • At the start, the paragraph should not be rendered.
  • After a click, the paragraph should be rendered.
  • After another click, the paragraph should not be rendered.

Finish the Message component by implementing this logic.

Solve Question

4. Focus

Easy  
React Components Public

The TextInput component renders an input element in the DOM and accepts a ref that is forwarded to that input element. Finish the FocusableInput component:

  • The component should accept a focused prop.
  • When the focused prop is changed from false to true, and the input is not focused, it should receive the focus.
  • If on mounting the focused prop is true, the input should receive the focus.
Solve Question

5. Todo List

Easy  
React Event Handling Public

Write a TodoList component that expects an items prop which is a list of objects, each with text and done properties.

TodoList also accepts an onItemClick function prop, which should be called when a user clicks an item in the list, if the item is not marked as done. Otherwise, the onItemClick should not be called and the click event itself should not be propagated further. The function should be called with the item object from the items list as the first parameter and the event as the second parameter.

Solve Question

6. Change Username

Hard  
React React Hooks Reference Hook Public

This application should allow the user to update their username by inputting a custom value and clicking the button.

The Username component is finished and should not be changed, but the App component is missing parts. Finish the App component so that the Username component displays the inputted text when the button is clicked.

The App component should use the React.useRef Hook to pass the input to the Username component for the input element and for the Username component.

For example, if the user inputs a new username of "John Doe" and clicks the button, the div element with id root should look like this:

<div><button>Change Username</button><input type="text"><h1>John Doe</h1></div>
Solve Question

7. Grocery App

Hard  
React Components Managing State React Hooks Public

You have a GroceryApp component, which receives a list of products, each one with name and votes. The app should render an unordered list, with a list item for each product. Products can be upvoted or downvoted.

By appropriately using React state and props, implement the upvote/downvote logic. Keep the state in the topmost component, while the Product component should accept props.

For example, passing the following array as products prop to GroceryApp [{ name: "Oranges", votes: 0 }, { name: "Bananas", votes: 0 }] and clicking the '+' button next to the Oranges should result in HTML like:

<div id="root">
  <ul>
    <li>
      <span>Oranges</span> - <span>votes: 1</span><button>+</button> <button>-</button>
    </li>
    <li>
      <span>Bananas</span> - <span>votes: 0</span><button>+</button> <button>-</button>
    </li>
  </ul>
</div>
Solve Question

8. Image Gallery App

Hard  
React Components Event Handling Managing State New Public

An image gallery is a set of images with corresponding remove buttons. This is the HTML code for a gallery with two images:

<div>
  <div class="image">
    <img src="https://bit.ly/3lmYVna">
    <button class="remove">X</button>
  </div>
  <div class="image">
    <img src="https://bit.ly/3flyaMj">
    <button class="remove">X</button>
  </div>
</div>

Implement the ImageGallery component that accepts a links prop and renders the gallery described above so that the first item in the links prop is the src attribute of the first image in the gallery. It should also implement the following logic: When the button is clicked, the image that is in the same div as the button should be removed from the gallery.

For example, after the first image has been removed from the gallery above, it's HTML code should look like this:

<div>
  <div class="image">
    <img src="https://bit.ly/3flyaMj">
    <button class="remove">X</button>
  </div>
</div>
Solve Question

If you feel ready, take one of our timed public React Interview Questions tests:
HTML/CSS

HTML/CSS and React Online Test (Easy / Hard)

HTML/CSS, JavaScript, and React Online Test (Easy / Hard)

HTML/CSS, React, and Node.js Online Test (Easy / Hard)

HTML/CSS, React, Node.js, and SQL Online Test (Easy / Hard)

React

React Online Test (Easy / Hard)

Not exactly what you are looking for? Go to our For Jobseekers section.
Dashboard Start Trial Sign In Home Tour Tests Questions Pricing For Jobseekers