Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.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
Reactjs React必须返回有效的React元素(或null)。您可能返回了未定义的,_Reactjs_React Redux - Fatal编程技术网

Reactjs React必须返回有效的React元素(或null)。您可能返回了未定义的,

Reactjs React必须返回有效的React元素(或null)。您可能返回了未定义的,,reactjs,react-redux,Reactjs,React Redux,这与您正在更改CoursePage的原型有关。如果你想使用PropTypes,你应该使用CoursePage.PropTypes={…}而不是prototype。此外,react版本>=15.5中不推荐使用propTypes。因此,您必须将其作为独立的依赖项安装。我觉得您的组件很合适。也许这是因为你正在改变CoursePage的原型?如果要使用PropTypes,应该使用CoursePage.PropTypes={…}而不是prototype。此外,在react版本>=15.5中不推荐使用Pro

这与您正在更改
CoursePage
的原型有关。如果你想使用PropTypes,你应该使用
CoursePage.PropTypes={…}
而不是
prototype
。此外,react版本>=15.5中不推荐使用
propTypes
。因此,您必须将其作为独立的依赖项安装。

我觉得您的组件很合适。也许这是因为你正在改变CoursePage的原型?如果要使用PropTypes,应该使用
CoursePage.PropTypes={…}
而不是prototype。此外,在react版本>=15.5中不推荐使用PropType。所以你必须把它作为一个独立的依赖项来安装。这就是问题所在,非常好,我想把它升级为一个答案。我在下面添加了我的答案。
import React, {PropTypes} from 'react';
import {connect} from 'react-redux';
import * as courseActions from '../../actions/courseActions';

class CoursePage extends React.Component {

  constructor(props, context) {
  super(props, context);

this.state = {
  course: {title: ""}
};

/*
 To enhance performance declare all the bindings here,
 otherwise if they are declare in the mark up binding
 will have to take place during rendering which will take
 performance hit.
*/

this.onTitleChange = this.onTitleChange.bind(this);
this.onClickSave = this.onClickSave.bind(this);
}

onTitleChange(event) {
const course = this.state.course;
course.title = event.target.value;
this.setState({
  course: course
  });
}
 onClickSave() {
this.props.dispatch(courseActions.createCourse(this.state.course));
}

courseRow(course, index) {
  return <div key={index}>{course.title}</div>;
}

render() {
return (<div>
  <div>
    <h1>Courses</h1>
    {this.props.courses.map(this.courseRow)}
    <h2>Add Course</h2>
  </div>
  <input
    type="text"
    onChange={this.onTitleChange}
    value={this.state.course.title}
  />
  <input
    type="submit"
    value="Save"
    onClick={this.onClickSave}
  />
</div>);
}
}

CoursePage.prototype = {
dispatch: PropTypes.func.isRequired,
courses: PropTypes.array.isRequired
};

const mapStateToProps = (state, ownProps) => {
return {
  courses: state.courses
};
};

// since second parameter is not provided, connect ejects connect prop
export default connect(mapStateToProps)(CoursePage);
invariant.js:44 Uncaught Error: CoursePage(...): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.
    at invariant (invariant.js:44)
    at ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:166)
    at ReactCompositeComponentWrapper.wrapper [as mountComponent] (ReactPerf.js:66)
    at Object.mountComponent (ReactReconciler.js:39)
    at ReactCompositeComponentWrapper.performInitialMount (ReactCompositeComponent.js:297)
    at ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:222)
    at ReactCompositeComponentWrapper.wrapper [as mountComponent] (ReactPerf.js:66)
    at Object.mountComponent (ReactReconciler.js:39)
    at ReactDOMComponent.mountChildren (ReactMultiChild.js:203)
    at ReactDOMComponent._createInitialChildren (ReactDOMComponent.js:628)