Stateless Component

suggest change

As the name implies, Stateless Components do not have any local state. They are also known as Dumb Components. Without any local state, these components do not need lifecycle methods or much of the boilerplate that comes with a stateful component.

Class syntax is not required. You can write const Name = (props) => ( ... ), or destructure the props you use. Stateless components are usually more concise.

Beneath is an example of two stateless components App and Title, with a demonstration of passing props between components:

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

const Title = ({title}) => (
  <Text>{title}</Text>
)    

const App = () => (
  <View>
    <Title title='Example Stateless Component' />
  </View>
)

AppRegistry.registerComponent('App', () => App)

Prefer this pattern when a component does not need state. Later optimisations can skip some of the work a class component does, which reduces memory allocations and unnecessary checks.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents