FlatList's ListFooterComponent doesn't render arrow function with refs
See original GitHub issueIs this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment:
OS: Linux 4.8
Node: 8.9.0
Yarn: 1.3.2
npm: 5.6.0
Watchman: 4.9.0
react-native: 0.48.4
react: 16.0.0-alpha.12
Steps to Reproduce
Create a FlatList with any items in content and a footer element with refs:
export default class MyElement extends Component {
constructor(props) {
super(props)
this.state = { someData: [{id: 1, content: 'foo'}, {id: 2, content: 'bar'}], myInputState: '' }
}
_renderItem = ({item}) => <Text>{item.content}</Text>
_renderFooter = () => {
return (
<TextInput ref='myReferencedInput' value={this.state.myInputState} onChangeText={(text) => this.setState({myInputState: text})} />
)
}
render () {
return (
<FlatList
data={this.state.somedata}
renderItem={this._renderItem}
keyExtractor={(item) => item.id}
ListFooterComponent={this._renderFooter}
/>
)
}
}
Expected Behavior
The footer content get’s rendered with no problems, as it would happen in ListView
Actual Behavior
“Stateless functions cannot have refs” error.
If I call this._renderFooter()
just below the FlatList
, it works, but is not what I want, I want it as a footer.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10
Top Results From Across the Web
React Native FlatList BUG? - Stack Overflow
Another Option will be to use arrow functions (Better) renderFooter = () =>{ return(<View/>); }. and then ListFooterComponent={this.
Read more >A deep dive into React Native FlatList - LogRocket Blog
FlatList is a React Native component that allows you to render lists with zero hassle and minimal code. Learn how to customize FlatList....
Read more >8 ways to optimize React native FlatList performance
1. Avoid arrow functions inline for renderItem ... Don't use arrow functions inline for renderItem of the FlatList. It's better if you avoid...
Read more >When should I use arrow functions with React?
Notice how constant doesn't change, while onChange does. This is because each call to render creates a new arrow function! Editor Preview.
Read more >How to use the FlatList Component — React Native Basics
First create a new function that renders the component you want in the header. You then want to actually render that header by...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just tried it and it worked, here is my working example
here is the console.log(this)
It works. Closing.