本文介绍了ReactNative - FlatList 直到滚动才更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用 FlatList
组件时遇到问题,该组件在滚动之前不会更新.
I have a problem with FlatList
component which does not update until scrolled.
我尝试将日志添加到 renderItem
和 keyExtractor
这两个方法都使用正确的数据调用,但列表没有更新.
I tried add log to renderItem
and keyExtractor
both methods called with correct data but list didn't update.
这是一个渲染方法:
render() {
const messages = this.props.messages
const message = this.props.message
return (
<View style={[styles.container]}>
<FlatList
ref={"flatList"}
contentContainerStyle={styles.list}
data={messages}
renderItem={(listItem) => {
return <MessageBuble message={listItem.item}/>
}}
keyExtractor={(item: Message) => {
return item.id
}}
/>
<View style={[styles.textInputContainer]}>
<TextInput
style={styles.textInput}
value={message}
multiline={true}
onChangeText={this.props.messageChanged}
/>
<Button title={"Odeslat"} onPress={() => {
if (this.props.sendMessage) {
this.props.sendMessage(this.props.message)
}
}}/>
</View>
</View>
)
}
推荐答案
在 FlatList 中添加 extraData 并重试
Add extraData in FlatList and retry
<FlatList
extraData={this.props}
....
这篇关于ReactNative - FlatList 直到滚动才更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!