Signup and Experience WorkikAI
Q1: What are the key differences between functional and class components in React?
Functional and class components are the two main types of components in React. Here are the key differences:
Functional Components: These are plain JavaScript functions that return JSX.
Class Components: These are ES6 classes that extend React.Component and must have a render method that returns JSX.
State and Lifecycle Methods:
Functional Components: Prior to React 16.8, functional components were stateless. With the introduction of hooks, they can now manage state and use lifecycle methods.
Class Components: These have built-in support for state and lifecycle methods (e.g., componentDidMount, shouldComponentUpdate).
Functional components with hooks can be more performant due to less overhead compared to class components.
Q2: What is JSX and why is it used in React?
JSX stands for JavaScript XML. It is a syntax extension for JavaScript that allows you to write HTML directly within JavaScript. JSX makes it easier to write and understand React components by providing a syntax similar to HTML.
JSX is used in React because it:
Q3: How does the virtual DOM work in React?
The Virtual DOM (VDOM) is a concept where a virtual representation of the UI is kept in memory and synced with the real DOM using a library such as ReactDOM. This process is known as reconciliation.
This approach minimizes direct DOM manipulations, resulting in better performance.
Q4: What are React hooks and why were they introduced?
React hooks are functions that let you use state and other React features in functional components. They were introduced in React 16.8 to address the following issues:
Q5: Explain the concept of props in React.
Props (short for properties) are read-only attributes used to pass data from a parent component to a child component in React. They allow components to be dynamic and reusable by providing a way to pass data and event handlers down the component tree.
In this example, message is a prop passed from ParentComponent to ChildComponent .
Props are immutable, meaning that a component cannot modify its own props. They should be used for data that a component should receive from its parent.
Please fill in the form below to submit your question.
â¡ Level Up in React: Explore Hooks, State Management, and more on Workik!
Q6: What is state in React and how is it different from props?
State is an object managed within a component that holds information that may change over the component's lifecycle. Unlike props, which are passed to a component from its parent, state is local to the component and can be updated with the setState method in class components or the useState hook in functional components.
Differences between State and Props:
Count: {this.state.count}
Q7: What is the context API in React and when would you use it?
The Context API in React provides a way to pass data through the component tree without having to pass props down manually at every level. It is useful for sharing data that needs to be accessed by many components at different nesting levels, such as themes, user authentication, or locale settings.
Provide Context Value:
Consume Context Value:
Using Context.Consumer :
Using useContext Hook (functional components):
Q8: How do you handle events in React?
Event handling in React is similar to handling events in DOM elements but with some syntactic differences. React events are named using camelCase, and you pass a function as the event handler rather than a string.
In functional components, you can handle events using hooks:
Q9: What are higher-order components (HOCs) in React?
A higher-order component (HOC) is a function that takes a component and returns a new component with additional props or functionality. HOCs are used to reuse component logic.
In this example, withLogging is an HOC that adds logging functionality to the MyComponent component.
Q10: What are React fragments and why would you use them?
React fragments let you group a list of children without adding extra nodes to the DOM. This is useful when rendering multiple elements from a component without wrapping them in an extra div or other container element.
Shorthand syntax for fragments:
Fragments are used to avoid unnecessary HTML elements in the DOM, which can simplify CSS styling and improve performance.
ð Your Workflow: Use Context-aware AI for Code Generation, Debugging, Unit Testing, & more.
Q11: What is the purpose of useEffect in React and how does it work?
The useEffect hook allows you to perform side effects in functional components. Side effects include data fetching, subscriptions, and manually changing the DOM. useEffect runs after the render and ensures the component logic is separate from the side effects.
You clicked {count} times
Q12: What is the useState hook and how do you use it in React?
The useState hook allows you to add state to functional components. It returns an array containing the current state value and a function to update that state.
In this example, count is the state variable and setCount is the function to update count . The initial state is set to 0.
Q13: Explain the concept of lifting state up in React.
Lifting state up is a pattern in React where you move state from child components to their closest common ancestor. This allows multiple components to share and synchronize their state.
Scenario: Suppose you have two sibling components that need to share the same state. Instead of managing state separately in each component, you lift the state up to their parent component and pass it down as props.
In this example, sharedState is lifted up to ParentComponent , allowing both ChildComponentA and ChildComponentB to access and synchronize the state.
Q14: What are controlled and uncontrolled components in React?
Controlled Components: These are components where React controls the form elements by keeping the form data in the component state. The value of the form element is set by the state and updated via events.
Uncontrolled Components: These are components where the form data is handled by the DOM itself. You can use a ref to access the form values.
Controlled components are preferred because they provide a more predictable and manageable way to handle form inputs.
Q15: How do you optimize performance in a large React application?
To optimize performance in a large React application, you can follow these best practices:
By applying these techniques, you can significantly improve the performance of your React application.
ðTop AI Available in one place: GPT, Claude, Gemini, Llama, Mistral, & more
Q16: What are React Portals and when would you use them?
React Portals provide a way to render children into a DOM node that exists outside the hierarchy of the parent component. They are useful for scenarios where you need to break out of the normal DOM hierarchy, such as rendering modals, tooltips, or dropdowns that overlay other content.
This is a modal content
In this example, the modal content is rendered into the modal-root div, which is outside the normal DOM hierarchy of the App component.
Q17: What are error boundaries in React and how do you implement them?
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed. They help prevent the entire application from crashing due to an error in a part of the UI.
Create an Error Boundary Component:
Wrap Your Components with Error Boundary:
Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
Q18: Explain the concept of reconciliation in React.
Reconciliation is the process by which React updates the DOM with the results of render output. When the state or props of a component change, React compares the newly returned element with the previously rendered one and updates the actual DOM only where there are differences.
Steps in Reconciliation:
Using keys, React can efficiently update the list when items are added, removed, or reordered.
Q19: What is the purpose of useReducer hook and how does it work?
The useReducer hook is an alternative to useState for managing complex state logic in functional components. It is particularly useful when the state depends on previous state values or when multiple state transitions share logic.
Count: {state.count}
In this example, useReducer manages the state transitions based on the dispatched actions.
Q20: Explain the difference between componentDidMount and useEffect in React.
componentDidMount is a lifecycle method used in class components, while useEffect is a hook used in functional components. Both are used to perform side effects, such as data fetching, subscriptions, or manually modifying the DOM, after the component has been rendered to the DOM.
ðUnlock Personalized AI Assistance by Adding Code Repos, API Schemas, DB Schemas, & more
The code itself does not contain any bugs. However, ensure that there are no external issues such as incorrect imports or render issues in the parent component.
The message is visible
The code itself is correct and should work as expected. Ensure there are no external issues such as incorrect imports or render issues in the parent component.
Add an empty dependency array to the useEffect hook to ensure the data is fetched only once when the component mounts.
Use React.memo to memoize the ListItem component.
Search query: {query}
Use a debouncing technique to delay the state update.
Search query: {displayedQuery}
Use React.memo to memoize the ChildComponent and prevent it from re-rendering unless its props change.
Explanation: setCount does not update the state immediately. It schedules an update, and the state updates are batched. Both setCount calls will be batched, and only the last one will be applied, resulting in count being incremented by 1 instead of 2.
Explanation: Using the functional update form of setCount ensures that the state updates are based on the previous state. This results in count being incremented by 1 twice, leading to an increment of 2 when the button is clicked twice.
React is a popular JavaScript library for building user interfaces, particularly single-page applications where data changes over time. It allows developers to create large web applications that can change data without reloading the page. React is maintained by Facebook and a community of individual developers and companies.
React was created by Jordan Walke, a software engineer at Facebook, and was first deployed on Facebook's newsfeed in 2011 and on Instagram in 2012. It was open-sourced at JSConf US in May 2013. Since then, React has grown significantly in popularity and is widely used in the industry. Trends show a steady increase in the demand for React developers due to the library's efficiency and the robust ecosystem surrounding it, including tools like Redux and React Native.
Popular frameworks and libraries associated with React include:
React is used for various purposes such as:
Tech roles associated with expertise in React include:
The salary for React professionals can vary based on experience, location, and specific role. Here are some general estimates based on the latest industry reports: Source: glassdoor.com indeed.com
Explore more on Workik
Interview Assistance
Top Frontend Developer Interview Questions
Top DevOps Interview Questions
Top PHP Interview Questions
Top C++ Interview Questions & Answers
Top Node.js Interview Questions & Answers
Top Angular Interview Questions & Answers
Top HTML & CSS Interview Questions & Answers
Top SQL Interview Questions
Top Python Interview Questions
Top Gallery Designs + Code
Top About Us Page Designs + Code
Top Contact Us Form Designs + Code
Top Pricing Page Designs + Code
Top FAQ Designs + Code
Top Testimonial Designs + Code
Top AI Tools for Productivity
Top Header(ATF) Designs + Code
Top Teams Section Designs + Code
Join developers who are using Workik and make your work incredibly easy.
Integration with Google Services
Don't miss any updates of our product.
© Workik Technologies LLP. 2026 All rights reserved.