Skip to content
tezvyn:
Menu

React Native Core Components: Your UI Building Blocks

Source: reactnative.devEasyHow cards are made

Think of Core Components as React Native's built-in LEGO bricks for UIs, translating your code into native Android and iOS views. Use them for layouts (View), text (Text), and lists (FlatList). The footgun: never use ScrollView for long lists.

Why it exists

To provide a unified, cross-platform API for building mobile UIs. Instead of writing separate Swift/Kotlin code for every button or text field, developers can use a single set of JavaScript components that render to native platform elements, speeding up development significantly.

The mental model

Think of Core Components as a standard library of UI building blocks. They are the fundamental pieces like View, Text, and Image that you combine to create your app's interface. React Native ensures that when you use a <Button>, it renders a native Android button on Android and a native iOS button on iOS, abstracting away the platform-specific implementation details.

How it works

Each Core Component is a JavaScript abstraction that maps to one or more native UI widgets on the target platform. When your app runs, React Native translates your component tree into instructions that create and manage the corresponding native views. For example, a <Text> component becomes a TextView on Android and a UILabel on iOS. This gives your app a native look, feel, and performance.

When to use it

Use Core Components for the vast majority of your UI development. They are the foundation for almost every screen. Key components include: View for creating containers and layouts, Text for displaying all text, TextInput for user input, Pressable for handling touch interactions, and Image for displaying pictures. For long lists of data, FlatList is the go-to for its performance benefits, as it only renders items currently on screen.

When not to use it

While Core Components cover most common cases, they are not exhaustive. If you need highly specialized functionality, like a map view, a custom video player, or a complex chart, you'll likely need to use a third-party library from the React Native community or write your own native module. Don't try to build everything from scratch using just View and Text if a specialized component already exists.

One canonical example

A simple login screen demonstrates the composition of Core Components. You would use a main View as the screen container. Inside it, you'd place two TextInput components for the username and password. Below them, a Pressable or Button component would handle the login action. All text labels, like "Username" or "Login", would be rendered using the Text component.

Interview question

For displaying long, scrolling lists of data in React Native, which component is recommended for optimal performance?

  • a.A third-party library, as core components lack advanced list virtualization.
  • b.A combination of View and Text components, managed with custom state.
  • c.ScrollView, as it provides basic scrolling functionality for all content.
  • d.FlatList, because it efficiently renders only the items currently visible on screen.Correct
Why?

FlatList is the recommended component for long lists because it optimizes performance by only rendering items currently visible on screen. ScrollView, while providing scrolling, renders all its children at once, which can lead to performance issues with extensive content.

Just read this? Test yourself on what you have been reading.

Read the original → reactnative.dev

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on react-native — each one lists the topics its interview covers.

See open roles