What are Presentatio...
What are Presentatio...
Presentational, or dumb, components in React Native are primarily concerned with how things look rather than how they work. They are designed to render UI elements based on the data they receive through props. Here are some key characteristics of presentational components:
Focus on UI: These components are mainly responsible for rendering markup and styles. They do not handle any business logic or data manipulation. Their primary role is to present information visually[1][2][3].
Stateless: Presentational components are usually stateless, meaning they do not manage their own state. If they do have state, it is only for UI-related concerns, such as toggling a dropdown menu or managing an input field's value[1][3][7].
Receive Data via Props: These components receive data and callback functions from their parent components through props. This makes them dynamic and reusable, as they can be used in different parts of the application with different data[1][2][3][7].
No Dependencies: Presentational components do not have dependencies on the rest of the application. They are self-contained and do not interact with external data sources or APIs directly[1][7].
Reusability: Due to their simplicity and lack of dependencies, presentational components are highly reusable across the application. This helps in maintaining consistency and reducing the amount of code duplication[1][2][3].
Easy to Test: Since they only render UI based on props and do not contain complex logic or state, presentational components are straightforward to test. Unit tests can easily verify that they render the correct output given a set of props[1][2][3].
Here is a simple example of a presentational component in React Native:
import React from 'react';
import { Text, View, StyleSheet } from 'react-native';
const WelcomeMessage = ({ name }) => {
return (
<View style={styles.container}>
<Text style={styles.text}>Welcome, {name}!</Text>
</Vie...
senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào