Reputation: 171
Suppose I designed a component for FlatList while using hook in React native. This; 1- It makes more sense to define off the page or 2- Is it above Return?
Is there any difference between these two users? Which one should be preferred in which situations?
//1
const Card = () => (..)
const App = () => {
const RenderItem = () => ( <Card /> )
return(
<FlatList
..
renderItem={RenderItem}
>
)}
//2
const App = () => {
const Card = () => (..)
return(
<FlatList
..
renderItem={Card}
>
)}
Upvotes: 0
Views: 49
Reputation: 546
I would suggest 2 because 1 is using extra method for returning the same component. I would use this way
const Card = ({ item }) => (<View key={item.key}></View>);
render(){
// ...
<FlatList
data={items}
renderItem={Card}
/>
// ...
}
Upvotes: 1