React native 反应本机路由器流量:在场景之间传递参数

React native 反应本机路由器流量:在场景之间传递参数,react-native,react-native-router-flux,React Native,React Native Router Flux,我有一个项目(作业)列表,当选择一个项目(作业)时,将打开一个新场景。我希望在不使用Redux的情况下,将所选项目的ID从包含列表的场景传递到包含所选项目(作业)详细信息的其他场景 路由器 import React from 'react'; import { Scene, Router } from 'react-native-router-flux'; import JobsList from './components/JobsList'; import Job from './compo

我有一个项目(作业)列表,当选择一个项目(作业)时,将打开一个新场景。我希望在不使用Redux的情况下,将所选项目的ID从包含列表的场景传递到包含所选项目(作业)详细信息的其他场景

路由器

import React from 'react';
import { Scene, Router } from 'react-native-router-flux';
import JobsList from './components/JobsList';
import Job from './components/Job';

const RouterComponent = () => {
  return (
    <Router>
      <Scene key="jobs" component={JobsList} initial />
      <Scene key="Job" component={Job} title="Test" />
    </Router>
  );
};
export default RouterComponent;
从“React”导入React;
从“react native Router flux”导入{Scene,Router};
从“./components/JobsList”导入作业列表;
从“./components/Job”导入作业;
常量路由组件=()=>{
返回(
);
};
导出默认路由组件;
工作清单

import React, { Component } from 'react';

export default class JobsList extends Component {
  render() {
    return (
      <TouchableOpacity onPress={() => { Actions.Job({ jobId: jobId }) }}>
      ...
      </TouchableOpacity>
    );
  }
}
import React,{Component}来自'React';
导出默认类作业列表扩展组件{
render(){
返回(
{Actions.Job({jobId:jobId})}>
...
);
}
}
工作

import React,{Component}来自'React';
导出默认类作业扩展组件{
构造函数(){
超级();
此.state={
作业:{}
};
axios.get(
//问题:this.props.jobId为空
`http://api.tidyme.dev:5000/${this.props.jobId}.json`,
{
标头:{Authorization:'Token-Token=123'}
}
).then(response=>this.setState({
工作:response.data
}));
}
render(){
返回(
{this.state.job.customer.firstName}
);
}
} 

如果要访问构造函数中的
this.props
,则应调用
super(props)

constructor(props) {
  super(props);
  console.log(this.props);
}

如果要访问构造函数中的
this.props
,应该调用
super(props)

constructor(props) {
  super(props);
  console.log(this.props);
}

最佳实践是将组件定义为纯函数:

const Job = ({ job, JobId}) => {
return (
   <Text>{job.customer.firstName}</Text>
  );
}

otherFunctions() {
  ...
}
const Job=({Job,JobId})=>{
返回(
{job.customer.firstName}
);
}
其他功能(){
...
}

最佳实践是将组件定义为纯函数:

const Job = ({ job, JobId}) => {
return (
   <Text>{job.customer.firstName}</Text>
  );
}

otherFunctions() {
  ...
}
const Job=({Job,JobId})=>{
返回(
{job.customer.firstName}
);
}
其他功能(){
...
}

谢谢。这是最佳实践还是我应该设置Redux来处理这个问题?如果道具被许多场景使用,那么Redux会更好。否则以上就足够了。谢谢。这是最佳实践还是我应该设置Redux来处理这个问题?如果道具被许多场景使用,那么Redux会更好。否则,上述内容就足够了。