ReactNative - FlatList not updated until scroll

╄→гoц情女王★ 提交于 2019-12-24 20:32:11

问题


I have a problem with FlatList component which does not update until scrolled.

I tried add log to renderItem and keyExtractor both methods called with correct data but list didn't update.

Here is a render method:

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>
    )
}

回答1:


Add extraData in FlatList and retry

<FlatList
    extraData={this.props}
    ....


来源:https://stackoverflow.com/questions/50204947/reactnative-flatlist-not-updated-until-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!