Components in React Native


Components in React Native Interview with follow-up questions

1. What are the different types of components in React Native?

There are two kinds: function components and class components — but in 2026 the expected answer is "function components with hooks are the standard; class components are legacy."

  • Function components are plain functions that return JSX. They manage state and side effects with hooks (useState, useEffect, useContext, etc.). This is what you write today.
  • Class components extend React.Component and use this.state, setState, and lifecycle methods (componentDidMount, etc.). Still supported for backward compatibility, but new code rarely uses them, and several old lifecycle methods are deprecated.

If you want to go further, you can also categorize by role rather than syntax — e.g. presentational vs container components, or RN's built-in core components (View, Text, Image, ScrollView, FlatList, Pressable) versus your custom components. But the core distinction interviewers are testing is function-vs-class, and the right framing is that hooks made functions the default.

↑ Back to top

Follow-up 1

Can you explain the difference between functional and class components?

Functional components are stateless and are defined as JavaScript functions. They receive props as input and return JSX as output. Class components, on the other hand, are stateful and are defined as ES6 classes. They have a render method that returns JSX and can have their own state and lifecycle methods.

Follow-up 2

What are pure components?

Pure components are a type of class component that optimize rendering performance. They only re-render when their props or state change. They implement a shouldComponentUpdate method that performs a shallow comparison of props and state to determine if a re-render is necessary.

Follow-up 3

When would you use a functional component over a class component?

Functional components are simpler and easier to read and write compared to class components. They are recommended for simple UI components that don't need state or lifecycle methods. They also have better performance because they don't have the overhead of creating and managing a class instance.

Follow-up 4

Can you give an example of a situation where you would use a class component?

Class components are useful when you need to manage state or use lifecycle methods. For example, if you have a component that needs to fetch data from an API and update its state based on the response, a class component would be a good choice. Here's an example:

import React, { Component } from 'react';

class DataFetcher extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: null
    };
  }

  componentDidMount() {
    fetch('https://api.example.com/data')
      .then(response => response.json())
      .then(data => this.setState({ data }));
  }

  render() {
    const { data } = this.state;
    return (
      <div>{data ? data.name : 'Loading...'}</div>
    );
  }
}

2. How do you create a component in React Native?

In modern React Native you create a component as a function component that returns JSX — not a class. Classes still work but are legacy.

import { View, Text, StyleSheet } from 'react-native';

function MyComponent({ name }) {
  return (

      Hello, {name}!

  );
}

const styles = StyleSheet.create({
  container: { padding: 16 },
});

export default MyComponent;

Points an interviewer listens for:

  • It's a function that takes props and returns JSX; state and side effects come from hooks (useState, useEffect) — no this, no render() method, no class.
  • UI uses native primitives (View, Text), and styling is a JS object via StyleSheet.create (better than inline objects since the style is created once).
  • You don't need to import React just for JSX (React 17+ transform). The old class MyComponent extends React.Component form is the legacy equivalent of this — fine to mention, but not what you'd reach for.
↑ Back to top

Follow-up 1

What is the significance of the render method in a component?

The render method is a required method in a React component. It is responsible for returning the JSX (JavaScript XML) that represents the component's UI. The render method is called whenever the component needs to be re-rendered, such as when its state or props change.

Here's an example of a render method:

render() {
  return (

      Hello, World!

  );
}

In this example, the render method returns a View containing a Text component with the text 'Hello, World!'.

Follow-up 2

What is the role of 'props' in components?

In React components, 'props' (short for properties) are used to pass data from a parent component to its child components. Props are read-only and should not be modified directly by the child components.

Here's an example of how props can be used:

import React from 'react';
import { View, Text } from 'react-native';

class MyComponent extends React.Component {
  render() {
    const { name } = this.props;
    return (

        Hello, {name}!

    );
  }
}

export default MyComponent;

In this example, the MyComponent component receives a prop called name and renders a Text component that displays the value of name.

Follow-up 3

Can you explain the lifecycle of a component?

The lifecycle of a React component refers to the different stages it goes through from initialization to unmounting. Each stage has lifecycle methods that can be overridden to perform certain actions.

Here are the main stages of a component's lifecycle:

  1. Mounting: The component is being created and inserted into the DOM.

    • constructor: Initializes the component's state and binds event handlers.
    • render: Returns the JSX that represents the component's UI.
    • componentDidMount: Called after the component has been rendered to the DOM.
  2. Updating: The component is being re-rendered due to changes in its props or state.

    • render: Returns the updated JSX.
    • componentDidUpdate: Called after the component has been re-rendered.
  3. Unmounting: The component is being removed from the DOM.

    • componentWillUnmount: Called before the component is unmounted.

These are just a few examples of the lifecycle methods available in React components. Each method serves a specific purpose and can be used to perform actions at different stages of a component's lifecycle.

3. What is a higher-order component in React Native?

A higher-order component (HOC) is a function that takes a component and returns a new, enhanced component — const Enhanced = withSomething(Component). It's a pattern for reusing cross-cutting logic (auth checks, data injection, logging) by wrapping components, not a built-in API.

function withLogger(Wrapped) {
  return function (props) {
    useEffect(() =&gt; console.log('mounted'), []);
    return ;
  };
}

The crucial 2026 framing: HOCs are largely legacy for logic reuse. Since hooks arrived, custom hooks (e.g. useAuth(), useFetch()) are the idiomatic way to share stateful logic — they avoid HOC pain points like wrapper nesting ("wrapper hell"), prop-name collisions, and lost ref forwarding.

So a strong answer: define the HOC pattern, note you'll still encounter it in libraries (e.g. older connect() from Redux, navigation/theme wrappers), but say you'd reach for a custom hook in new code. Mentioning that you know when HOCs are still reasonable (wrapping a third-party component you don't control) shows real judgment.

↑ Back to top

Follow-up 1

Can you give an example of a higher-order component?

Sure! Here's an example of a higher-order component that adds a loading state to a component:

import React from 'react';

const withLoading = (WrappedComponent) =&gt; {
  return class extends React.Component {
    state = {
      isLoading: true
    };

    componentDidMount() {
      setTimeout(() =&gt; {
        this.setState({ isLoading: false });
      }, 2000);
    }

    render() {
      if (this.state.isLoading) {
        return <div>Loading...</div>;
      }

      return ;
    }
  };
};

export default withLoading;

In this example, the withLoading higher-order component adds a loading state to the wrapped component. It sets an initial isLoading state to true, and after 2 seconds, it updates the state to false and renders the wrapped component.

Follow-up 2

What are the benefits of using higher-order components?

There are several benefits of using higher-order components in React Native:

  1. Reusability: HOCs allow you to reuse component logic across multiple components. This helps in keeping your codebase DRY (Don't Repeat Yourself).

  2. Separation of Concerns: HOCs enable you to separate the concerns of a component. You can extract common logic into a higher-order component and keep the component itself focused on rendering UI.

  3. Code Organization: HOCs provide a way to organize your code by separating concerns into smaller, reusable functions.

  4. Composition: HOCs can be composed together to create more complex behaviors. This allows you to build up functionality by combining multiple HOCs.

Overall, using higher-order components can improve the maintainability and reusability of your React Native code.

Follow-up 3

When would you use a higher-order component?

You can use a higher-order component in React Native in various scenarios:

  1. Code Reusability: If you have a piece of logic that is used by multiple components, you can extract that logic into a higher-order component and reuse it across those components.

  2. Cross-Cutting Concerns: If you have a concern that cuts across multiple components, such as authentication or data fetching, you can implement it as a higher-order component and apply it to the relevant components.

  3. Conditional Rendering: If you need to conditionally render a component based on certain conditions, you can use a higher-order component to handle the logic for conditional rendering.

  4. Performance Optimization: Higher-order components can be used for performance optimizations, such as memoization or caching of expensive computations.

In general, higher-order components are useful when you want to separate concerns, reuse code, or add additional functionality to a component without modifying its implementation.

4. How do you handle events in React Native components?

In React Native you handle events by passing a handler function to a component's event prop. There's no DOM event system — instead each component exposes specific props:

  • Touch: onPress, onLongPress, onPressIn/Out on touchables like Pressable, TouchableOpacity, Button.
  • Text input: onChangeText (gives you the string directly), onSubmitEditing, onFocus, onBlur.
  • Scroll/list: onScroll, onEndReached, onRefresh.
function Counter() {
  const [count, setCount] = useState(0);
  return (
     setCount((c) =&gt; c + 1)}&gt;
      Pressed {count} times

  );
}

Gotchas interviewers look for:

  • Pass the function reference (onPress={handlePress}), don't call it (onPress={handlePress()} runs it on render).
  • For costly handlers passed to memoized children, wrap them in useCallback to keep referential stability.
  • onChangeText already passes the text, unlike web's onChange which passes an event object — a common slip for people coming from React DOM.
  • Pressable is the recommended, flexible primitive in modern RN; the older Touchable* components still work but Pressable is preferred.
↑ Back to top

Follow-up 1

Can you explain how event handling works in React Native?

In React Native, event handling works by attaching event handlers to components or elements. When the specified event occurs, the corresponding event handler is called. For example, if you have a button component with an onPress prop set to a function, that function will be called when the button is pressed. Event handling in React Native is similar to event handling in web development, but with some differences due to the native environment.

Follow-up 2

What is event propagation in React Native?

Event propagation in React Native refers to the process of an event being passed from a child component to its parent components. When an event occurs in a child component, it can be propagated up the component hierarchy to its parent components. This allows parent components to handle events that occur in their child components. Event propagation follows the same principles as event bubbling in web development.

Follow-up 3

How can you stop an event from propagating?

To stop an event from propagating in React Native, you can use the stopPropagation method. This method can be called within an event handler to prevent the event from being passed to parent components. For example, if you have a button inside a parent component and you don't want the button's onPress event to trigger the parent component's event handler, you can call stopPropagation within the button's event handler.

5. What is the context API in React Native and how does it relate to components?

The Context API lets you share data across the component tree without passing props through every level ("prop drilling"). It's part of React core, so it works the same in React Native.

Modern usage is createContext + a Provider + the useContext hook — not the old Consumer render-prop, which is legacy:

const ThemeContext = createContext('light');

function App() {
  return (



  );
}

function Screen() {
  const theme = useContext(ThemeContext); // reads nearest Provider's value
  return {theme};
}

How it relates to components: any component under the Provider can read the value directly via useContext, which is great for app-wide concerns like theme, auth/user, or locale.

The gotcha interviewers want: Context isn't a state manager and isn't free. When the Provider's value changes, every consumer re-renders — so don't put rapidly-changing or large state in one giant context. Split contexts, memoize the value, or reach for a dedicated library (Zustand/Jotai/Redux Toolkit) when you need selective subscriptions or complex shared state.

↑ Back to top

Follow-up 1

Can you give an example of how you would use the context API?

Sure! Here's an example of how you can use the context API in React Native:

// First, create a new context
const MyContext = React.createContext();

// Then, create a provider component
const MyProvider = ({ children }) =&gt; {
  const data = 'Hello, world!';

  return (

      {children}

  );
};

// Finally, use the context in a consumer component
const MyConsumer = () =&gt; {
  const data = useContext(MyContext);

  return {data};
};

// Now, you can use the provider and consumer in your app
const App = () =&gt; {
  return (



  );
};

In this example, we create a new context called MyContext using the React.createContext() function. We then define a provider component called MyProvider that wraps its children with the MyContext.Provider component and provides a value of 'Hello, world!'. Finally, we create a consumer component called MyConsumer that uses the useContext hook to access the value from the context and render it in a Text component.

Follow-up 2

What are the benefits of using the context API?

There are several benefits of using the context API in React Native:

  1. Avoids prop drilling: The context API allows you to pass data down the component tree without having to pass it through every intermediate component. This helps to keep your code clean and avoids the need for excessive prop drilling.

  2. Simplifies state management: By using the context API, you can centralize your state management and make it easier to share data between components. This can be especially useful for global state management or sharing data between unrelated components.

  3. Improves code maintainability: The context API makes it easier to understand and maintain your code by providing a clear and explicit way to share data between components. It reduces the complexity of passing props through multiple levels of components and makes your code more readable and maintainable.

  4. Flexible and scalable: The context API is flexible and can be used in a variety of scenarios. It can be easily extended and customized to fit the specific needs of your application. Additionally, it can scale well as your application grows, allowing you to easily add or modify the shared data without impacting the entire component tree.

Follow-up 3

How does the context API compare to Redux?

The context API and Redux are both state management solutions in React Native, but they have some key differences:

  1. Complexity: Redux is a more powerful and complex state management library compared to the context API. It provides a set of additional features like middleware, reducers, and actions, which can be useful for managing complex state and handling asynchronous operations. On the other hand, the context API is simpler and more lightweight, making it easier to get started with and understand.

  2. Scalability: Redux is designed to handle large-scale applications with complex state management needs. It provides a centralized store and a predictable state container, which can be beneficial for managing state in large applications. The context API, on the other hand, is more suitable for smaller applications or cases where you only need to share data between a few components.

  3. Community and ecosystem: Redux has a large and active community with a rich ecosystem of third-party libraries and tools. It has been widely adopted and has a lot of resources and documentation available. The context API, although growing in popularity, does not have the same level of community support and ecosystem.

In summary, if you have a small to medium-sized application with simple state management needs, the context API can be a good choice. However, if you have a large-scale application with complex state management requirements, Redux might be a better fit.

6. How does styling work in React Native? (StyleSheet, Flexbox, units)

RN has no CSS or DOM. You style with JavaScript objects — typically via StyleSheet.create, which validates styles and lets RN reference them by ID.

const styles = StyleSheet.create({
  card: { flex: 1, padding: 16, backgroundColor: '#fff' },
  title: { fontSize: 18, fontWeight: '600' },
});
Hi

Key points interviewers look for:

  • Flexbox is the layout system (powered by Yoga). Default flexDirection is column (not row like the web) — a classic gotcha.
  • Property names are camelCase (backgroundColor, not background-color); there are no cascading selectors or stylesheets — styles are local and explicit.
  • Dimensions are unitless density-independent pixels (dp), not px/rem. Use Dimensions/useWindowDimensions or percentages for responsiveness.
  • style accepts an array ([base, condition &amp;&amp; override]) for composition; later entries win.
  • For shared theming/utility styling, teams often add libraries (NativeWind/Tailwind, Tamagui, styled-components), but the core mental model is JS-object styles + Flexbox.
↑ Back to top

Live mock interview

Mock interview: Components in React Native

Intermediate ~5 min Your own free AI key

Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.