Sunday, 2 April 2017

Cant type in InputType 'text' in React

i am using NodeJS.

Here is my componenet in my coursePage.js . the problem is when when i run it I cant type in my InputType, although i cant see any error in my code (neither the concole show me nothing).. can comeone help me figure my problem ?

import React , {PropTypes} from 'react';
import {connect} from 'react-redux';
import * as courseActions from '../../actions/courseActions';

class coursesPage extends React.Component{

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

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

    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>
        <h1>Courses</h1>
        {this.props.courses.map(this.courseRow)}
        <h2>Add Course</h2>
        <input
          type="text"
          onChange={this.onTitleChange}
          value={this.state.course.title}/>

        <input
          type="submit"
          value="Save"
          onClick={this.onClickSave}/>
      </div>
    );
  }
}
coursesPage.propTypes = {
  dispatch: PropTypes.func.isRequired,
  courses: PropTypes.array.isRequired
};

function mapStateToProps(state, ownProps){
  return{
    courses : state.courses
  };

}
export default connect(mapStateToProps)(coursesPage);



via Tal

No comments:

Post a Comment