还原/反应.您必须将一个组件传递给 connect 返回的函数.而是收到未定义 [英] Redux/React. You must pass a component to the function returned by connect. Instead received undefined

查看:65
本文介绍了还原/反应.您必须将一个组件传递给 connect 返回的函数.而是收到未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这个话题 您必须将一个组件传递给 connect 返回的函数.而是收到未定义,但这与我的情况无关.

I see this topic You must pass a component to the function returned by connect. Instead received undefined, but it's does not about my case.

所以,我无法理解我的演示文稿/容器连接有什么问题?

So, I cannot undurstand what is the wrong with my presentation/container connection?

我将它们相互连接起来,但出现错误:您必须将一个组件传递给 connect 返回的函数.而是收到未定义

I connect they one to each other, but I get an error: You must pass a component to the function returned by connect. Instead received undefined

/* 组件 */

import React from 'react';
import AddTodo from '../../Actions/AddTodo'
import TodoFormAdd from '../../Containers/TodoFormAdd'

class TodoForm extends React.Component{   
    constructor(props) {
        super(props);
        this.handleSubmit = this.handleSubmit.bind(this);
    }

    handleSubmit(e) {
        e.preventDefault();

        document.querySelector('input').input.value = '';   
        TodoFormAdd(this.props.store, this.input.value);
    }

    render() {
        return (
            <form id="tp" onSubmit={this.handleSubmit}>
                <input type="text" placeholder="Your text" />
                <button type="submit">Add todos</button>
            </form>
        );  
    }
}

export default TodoForm;

/* 容器 */

import { connect } from 'react-redux';
import TodoForm from '../Components/TodoForm/TodoForm'
import AddTodo from '../Actions/AddTodo'

let TodoFormAdd = (store, input) => store.dispatch(AddTodo(input));

export default connect(TodoFormAdd)(TodoForm);

推荐答案

已解决:

问题出在一次运行中更接近调用这两个代码.

The problem had been in the closer of invoke these two codes in one time of running.

所以下一个是链:

  1. 我们启动组件TodoForm,该组件也尝试导入TodoFormAdd;
  2. TodoFormAdd 还没有让参数起作用,开始开始崩溃.
  3. 然后 TodoForm 无法自行完成编译并崩溃.
  1. We start the component TodoForm that also try to import TodoFormAdd;
  2. TodoFormAdd does not already got the parameters to work and start begins to crash.
  3. Then TodoForm cannot finish compilation themself and aslo crash.

而且就是这样.所以我只是删除了 TodoForm 中的 import TodoFormAdd ,一切都变得很好.

And that it. So I just delete import TodoFormAdd in TodoForm and and everything became good.

感谢大家的帮助!

这篇关于还原/反应.您必须将一个组件传递给 connect 返回的函数.而是收到未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆