Components
Like React for the Web, React Native uses a component-based architecture and all code
lives inside the components.
Components are reusable function-like objects that are used to describe the native components that are displayed. React Native components always have a render method, some properties and a state.
React Native offers both cross-platform and platform-specific components. For example, the iOS and Android applications can both use a React component named, which
gets rendered as UIView on iOS and as a View on Android. Some components are only
available for a specific platform, for example the renders the standard
date picking component for iOS, while on Android has to be used.
React Native has variety of components similar to basic HTML components that are used
when developing with React for the Web or with pure HTML for the web in general. Most
common HTML components, their use cases and React Native counterparts are listed in.
HTML components and their corresponding React Native components
Components are created simply by creating a class that extends the React.Component class, and has a render() method that returns JSX.
Creating a React Native component:
class HelloWorldComponent extends React.Component {
render(){
return(
<View>
<Text> Hello World </Text>
<View>
);
}
}
Components are reusable function-like objects that are used to describe the native components that are displayed. React Native components always have a render method, some properties and a state.
React Native offers both cross-platform and platform-specific components. For example, the iOS and Android applications can both use a React component named
Purpose | HTML Component | React Native Component |
Dividing content | <div> | <View> |
Displaying Image | <img> | <Image> |
Paragraph of text | <span>,<p> | <Text> |
List, unordered, ordered | <li>, <ul>,<ol> | <ListView> |
Control Elements | <a>,<button> | <TouchableHighlight> |
HTML components and their corresponding React Native components
Components are created simply by creating a class that extends the React.Component class, and has a render() method that returns JSX.
Creating a React Native component:
class HelloWorldComponent extends React.Component {
render(){
return(
<View>
<Text> Hello World </Text>
<View>
);
}
}
Comments
Post a Comment