Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在componentWillMount或componentDidMount中使用异步redux操作对未呈现的本机组件作出反应_Javascript_Reactjs_React Native_Redux - Fatal编程技术网

Javascript 在componentWillMount或componentDidMount中使用异步redux操作对未呈现的本机组件作出反应

Javascript 在componentWillMount或componentDidMount中使用异步redux操作对未呈现的本机组件作出反应,javascript,reactjs,react-native,redux,Javascript,Reactjs,React Native,Redux,我有一个用CRNA创建的react本机应用程序。在componentDidMount或componentWillMount中调用API以获取更新速率时,该组件不再呈现。我正在使用react本机路由器流量进行路由。这些操作是为配合redux axios中间件而构建的 组成部分: ... class CreateUser extends React.Component { constructor(props) { super(props); this.state = { error };

我有一个用CRNA创建的react本机应用程序。在componentDidMount或componentWillMount中调用API以获取更新速率时,该组件不再呈现。我正在使用react本机路由器流量进行路由。这些操作是为配合redux axios中间件而构建的

组成部分:

...
class CreateUser extends React.Component {
  constructor(props) {
  super(props);
  this.state = { error };

  this.onSubmit = this.onSubmit.bind(this);
}

componentDidMount() {
  this.props.getCountries();
}

onSubmit(data) {
  this.setState({error: error}); //clear out error messages

  this.props.createUser(data)
}

render() {
  return (
    <View style={styles.container}>
      <PageHeader
        title={'Create User'}
        subtitle={'Create a user under your default affiliate link.'}
        backButton />
      <Form fields={fields}
        showLabel={false}
        onSubmit={this.onSubmit}
        buttonTitle={"Create User"}
        error={this.state.error}/>
    </View>
  );
}

export default connect(null, { createUser, getCountries })(CreateUser);
行动:

...
export function getCountries() {
  return {
    type: t.GET_COUNTRIES,
      payload: {
        request: {
        url: 'data/countries',
      },
    },
  };
};
...

当组件路由到时,操作将运行,有效负载将记录到控制台,但组件不会呈现。我是个新手,应该将动作发送到其他地方吗?

它们不会呈现,因为您没有在任何地方呈现它们。您所做的只是添加
this.props.getCountries()调用它,但视图中没有任何内容

您需要在组件中执行类似的操作

函数mapstatetops(state){
返回{countries:state.theReducerName.countries}
导出默认连接(MapStateTops,{createUser,getCountries})(createUser)


然后在渲染中,您可以使用
this.props.countries

它们不会渲染,因为您没有在任何地方渲染它们。您所做的只是添加
this.props.getCountries()调用它,但视图中没有任何内容。它们将在子组件中呈现。组件本身未渲染。因此,在此之前的组件将保持呈现状态,但控制台将记录结果。我知道它不再渲染国家,但它不再渲染任何东西。
...
export function getCountries() {
  return {
    type: t.GET_COUNTRIES,
      payload: {
        request: {
        url: 'data/countries',
      },
    },
  };
};
...