Json 本机反应,将道具从一个组件导航到另一个组件

Json 本机反应,将道具从一个组件导航到另一个组件,json,api,react-native,fetch,Json,Api,React Native,Fetch,handleShowMatchFacts=id=>{ //console.log('match',id) 回传(`http://api.football-api.com/2.0/matches/${id}?授权=565ec012251f932ea4000001fa542ae9d994470e73fdb314a8a56d76`) .然后(res=>{ //console.log('match facts',match facts) 这个是.props.navigator.push({ 标题:"比赛

handleShowMatchFacts=id=>{
//console.log('match',id)
回传(`http://api.football-api.com/2.0/matches/${id}?授权=565ec012251f932ea4000001fa542ae9d994470e73fdb314a8a56d76`)
.然后(res=>{
//console.log('match facts',match facts)
这个是.props.navigator.push({
标题:"比赛",,
组件:MatchPage,
passProps:{matchInfo:res}
})
//console.log(res)
}) 
}

在React中,您永远不会直接更改道具。您必须始终通过setState更改状态,并将状态作为道具传递给组件。这允许React为您管理状态,而不是手动调用

在api调用的结果中,设置组件状态:

this.setState({
    title: 'Match',
    component: MatchPage,
    matchInfo: res
}
class FooComponent extends Component {
    constructor(props) {
        super(props);
    }
    componentWillMount() {
        console.log(this.props.title);
        console.log(this.props.matchInfo);
        // Etc.
    }
}
然后根据需要将状态传递到子组件中

render() {
        return(
            <FooComponent title={this.state.title} matchInfo={this.state.matchInfo} />
        );
    }
如果需要在组件本身内部引用这些值,请引用状态,而不是道具

this.state.title;
this.state.matchInfo;

请记住,组件管理自己的状态,并根据需要将该状态作为道具传递给子级

假设您正在接收json对象作为响应,则需要在获取值之前解析响应

var resp = JSON.parse(matchInfo);
body = resp['_bodyInit'];

嘿,伙计,谢谢你的回复,但是你的回答没有帮到我,我尝试了你的方法,但是应用程序可以导航到新组件谢谢你!!!你解决了我的问题!!谢谢你回复我,兄弟!!伟大的很高兴这有帮助。