如何将道具传递给TabBarIOS中的另一个组件?

时间:2017-05-05 03:27:16

标签: json react-native state tabbarios

      <TabBarIOS.Item
        icon={{uri: base64Icon, scale: 3}}
        title="Match Facts"
        badge={this.state.notifCount > 0 ? this.state.notifCount : undefined}
        badgeColor="black"
        selected={this.state.selectedTab === 'matchFacts'}
        onPress={() => {
          this.setState({
            selectedTab: 'matchFacts',
          });
        }}>
        <MatchFacts propsToCall={this.props.matchFacts}/>
      </TabBarIOS.Item>

==================

MatchFacts组件

constructor(props) {
super(props)

this.state = {
  selectedTab: 'matchFacts',
  matchInfo: {}
}

  }

  componentWillMount(){
        this.setState({
          matchInfo : this.props.matchFacts
        })

   console.log(this.state.matchInfo)
  }

  componentDidMount(){
console.log('did mount ' + this.state.matchInfo.localteam_name)
  }

在我的TabBar.Item选项卡中,我想传入this.props.matchFacts,以便可以在MatchFacts组件中使用它。当我把它传递到包含&#34; MatchFacts propsToCall = {this.props.matchFacts}&#34;我认为理论上应该将道具传递给下一个组件。当我尝试访问MatchFacts组件中的道具时,它不起作用。我相信我在这里提供的代码行中做错了。

0 个答案:

没有答案