Loading

Quipoin Menu

Learn • Practice • Grow

react / React Components
interview

Q1. What are React components?
React components are independent, reusable pieces of UI. They can be functions or classes that optionally accept inputs (props) and return React elements describing what should appear on the screen. Components allow you to split the UI into smaller, manageable parts.

Q2. What are the two types of React components?
The two types are functional components (JavaScript functions that return JSX) and class components (ES6 classes that extend React.Component and have a render method). With the introduction of hooks, functional components can now manage state and side effects, making them more popular.

Q3. How do you create a simple functional component?
A functional component is a JavaScript function that returns JSX. Example: function Welcome(props) { return

Hello, {props.name}

; }. You can also use arrow functions: const Welcome = (props) =>

Hello, {props.name}

.

Q4. What is the render method in class components?
In class components, the render() method is required. It returns the JSX that describes the UI. The render method is called whenever the component's state or props change, and it must be pure (no side effects). Example: class Welcome extends React.Component { render() { return

Hello

; } }.

Q5. How do you compose components in React?
Components can be composed by nesting them inside each other. For example, an App component can render a Header, Main, and Footer component. Props are used to pass data from parent to child components. This composition allows building complex UIs from simple building blocks.