Skip to content

React Component Design Interview Guide

A React component is a reusable piece of UI that encapsulates its own structure, logic, and styling.

function Button() {
return <button>Click Me</button>;
}

A component is the fundamental building block of React applications. It promotes reusability, maintainability, and separation of concerns by encapsulating UI and behavior into independent units.


function Welcome() {
return <h1>Hello</h1>;
}
class Welcome extends React.Component {
render() {
return <h1>Hello</h1>;
}
}

Modern React primarily uses functional components with Hooks because they are simpler and provide all lifecycle capabilities.


A well-designed component should be:

  • Reusable
  • Single Responsibility
  • Maintainable
  • Testable
  • Scalable

Bad

UserDashboard

Handles:

  • API calls
  • Rendering
  • Validation
  • Business logic

Good

flowchart TD
    A[UserDashboard] --> B[UserProfile]
    A --> C[UserStats]
    A --> D[UserActions]

Each component has one responsibility.


A component should have only one reason to change.

function UserComponent() {
// fetch user
// display user
// update user
}
UserList
UserDetails
UserForm

Applying SRP improves reusability, testing, and reduces coupling.


Create a new component when:

  • UI repeats
  • Logic repeats
  • Component becomes large
  • Reusability is needed

Instead of:

<Card1 />
<Card2 />
<Card3 />

Use:

<Card title="A" />
<Card title="B" />
<Card title="C" />

  • API calls
  • State management
  • Business logic
  • UI rendering only
flowchart TD
    A[UserContainer] --> B[UserCard]

Passing props through multiple levels.

flowchart TD
    A[App] --> B[Parent]
    B --> C[Child]
    C --> D[GrandChild]

Example:

<App user={user} />

Solutions:

  • Context API
  • Redux
  • Zustand

Use configurable props.

<Button text="Save" variant="primary" />

Avoid hardcoding.

<button>{text}</button>

Composition combines smaller components into larger ones.

<Card>
<Header />
<Body />
<Footer />
</Card>

Benefits:

  • Reusability
  • Flexibility
  • Maintainability

React recommends composition over inheritance.

<Card>
<UserProfile />
</Card>

function Card({ children }) {
return <div>{children}</div>;
}

Usage:

<Card>
<h1>Hello</h1>
</Card>

Separate concerns:

UserForm
- FormFields
- Validation
- API Service

Recommended libraries:

  • React Hook Form
  • Formik

Use custom hooks.

function useFetch(url) {
// fetch logic
}
const data = useFetch("/users");

const UserCard = React.memo(({ user }) => {
return <div>{user.name}</div>;
});
const result = useMemo(() => expensiveCalc(), []);
const handleClick = useCallback(() => {}, []);

Traditional:

src
- components
- pages
- hooks
- services
- contexts
- utils
- store
- routes

Feature-based:

features
- users
- components
- hooks
- api
- pages
- products
- orders

Component design decisions around forms often come back to this distinction. See the React Interview Study Guide for the controlled vs uncontrolled comparison and code examples.


<Modal
isOpen={isOpen}
onClose={closeModal}
>
<UserForm />
</Modal>

Design considerations:

  • Accept children
  • Configurable props
  • Independent state
  • Reusable

<Table
data={users}
columns={columns}
/>
const columns = [
{ key: "name", title: "Name" },
{ key: "email", title: "Email" }
];

Benefits:

  • Dynamic rendering
  • Reusable
  • Customizable

Lift state to the common parent.

flowchart TD
    P[Parent]
    P --> A[Child A]
    P --> B[Child B]

Alternatives:

  • Context API
  • Redux
  • Zustand

<Button
variant="primary"
size="large"
loading={true}
disabled={false}
onClick={handleClick}
>
Save
</Button>

Consider:

  • Accessibility (ARIA)
  • Loading state
  • Disabled state
  • Theme support
  • Dark mode
  • Responsive design
  • Testability

Frequently Asked Senior Interview Questions

Section titled “Frequently Asked Senior Interview Questions”
  1. How would you design a reusable table component?
  2. How would you build a design system in React?
  3. Smart vs Dumb components?
  4. Composition vs Inheritance?
  5. How do you avoid prop drilling?
  6. How do you structure a large React application?
  7. How do you design scalable forms?
  8. How do you share business logic across components?
  9. How would you design reusable modals, dropdowns, and buttons?
  10. What are the common mistakes in component design and how do you avoid them?
  • Build small, reusable components with a single responsibility.
  • Prefer composition over inheritance.
  • Share logic using custom hooks rather than duplicating code.
  • Design configurable components using props and children.
  • Organize large applications using a feature-based folder structure.
  • Optimize rendering with React.memo, useMemo, and useCallback.