【发布时间】:2019-11-22 09:12:54
【问题描述】:
您好,我怎样才能使用来自Home 组件的数据在Profil 组件中工作。我在Home 组件中有一个状态,我在其中存储来自网络服务的数据。
class Accueil extends React.Component {
constructor(props) {
super(props);
this.state = {
refreshing: false,
latitude:null,
longitude:null,
dataSource:[],
error:null,
appState: AppState.currentState,
currentIndex: 0,
}
this.displayPosition = this.displayPosition.bind(this);
}
getData(){
fetch("SomeURL")
.then(res => res.json())
.then(result => {
return(
this.setState({
dataSource: result
}));
})
.catch(error => {
console.error(error)
})
}
render() {
return (
<SafeAreaView style={{ flex:1 }}>
<View style={styles.main_container}>
<FlatList style={styles.flatList}
data={this.state.dataSource}
extraData = {this.state}
keyExtractor={(item, index) => item.MembreId}
renderItem={(item) => <UserItem user={item} displayDetailForUser={this._displayDetailForUser} displaySwipe = {this._displaySwipe}/>}
numColumns={numColumns}
refreshing={this.state.refreshing}
onRefresh={this.handleRefresh} />
</View>
</SafeAreaView>
)
}
}
如何在Profil 组件中使用this.state.dataSource 以便.map 使用数据的刷卡者?
【问题讨论】:
-
您在将值传递给配置文件组件时遇到问题吗??'
-
是的,我无法在 Profil 组件中传递整个数据源
-
但是,你必须声明你的
displayPosition方法。 -
不是我已经声明了displayPosition但是我没有在这里写,否则会太长
标签: react-native react-native-swiper