score:0

Accepted answer
case EDIT_ISSUE:
return {
  ...state,
  Issues: state.Issues // re-asssign issues
};

score:0

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { updateIssue, fetchIssue } from '../actions/IssueAction';

class EditIssue extends Component {
  state = {
    description: '',
    severity: '',
    assignedTo: '',
  };

  componentDidMount() {
// you need to figure out a way to have id here ... as a props or state 
const { id, fetchIssue } = this.props;
 fetchIssue(id)


  }

componentDidUpdate() {
if(this.props.Issues.length ){ 
const { description, severity, assignedTo } = this.props.Issues;
    this.setState({
      description: description,
      severity: severity,
      assignedTo: assignedTo,
    });

}

}

  onChange = (e) => {
    this.setState({
      [e.target.name]: e.target.value,
    });
  };
  onSubmit = (e) => {
    e.preventDefault();

    const post_Issue = {
      description: this.state.description,
      severity: this.state.severity,
      assignedTo: this.state.assignedTo,
    };

    this.props.updateIssue(post_Issue);

    window.location = '/';
  };

  render() {
if(!this.props.Issue) return <div> return something else since this is before node js respond </div>;
    return (
      <div>
        <h3>Add New Issue</h3>
        <form onSubmit={this.onSubmit}>
        // your form fields...
        </form>
      </div>
    );
  }
}

const mapStateToProps = (state) => ({
  Issues: state.Issues,
});

export default connect(mapStateToProps, { updateIssue, fetchIssue })(EditIssue);


Related Query

More Query from same tag