0

嗨,如何Profil使用来自组件的数据让 swiper 在组件中工作Home。我在组件中有一个状态,Home我在其中存储来自 Web 服务的数据。

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

我如何this.state.dataSourceProfil组件中.map使用数据来刷卡?

4

1 回答 1

0

要将值从一个组件传递到另一个组件,您可以使用以下代码 -

this.props.navigation.navigate('<Your Screen Name>', {
    dataSource: this.state.dataSource
});

现在在您的组件中,您可以访问数据存储区,如下所示:

var tempDataSource = [...this.props.navigation.state.params.dataSource]

通过直接访问 this.props.navigation.state.params.dataSource这个变量来使用它,或者您可以像上面一样将它保存在另一个变量中并与您的 swiper 一起使用。

我希望这会有所帮助,谢谢:)

于 2019-11-22T09:38:13.490 回答