Skip to content
Permalink
Browse files

with redux & added delete functionality

  • Loading branch information...
“koushik-bitzop”
“koushik-bitzop” committed Jun 12, 2019
1 parent 47070a7 commit cd9712a89c4de7625cecbd6e494199f0ad5dd20f
Showing with 28 additions and 6 deletions.
  1. +8 −0 src/allactions.js
  2. +7 −0 src/allreducer.js
  3. +12 −4 src/components/FormdataTable.js
  4. +1 −2 src/components/SignupForm.js
@@ -6,3 +6,11 @@ export function addNewEmp(payload){
} }
return action; return action;
} }

export function delEmp(index){
const action = {
type: "DEL_EMP",
index
}
return action;
}
@@ -5,6 +5,13 @@ function empdatareducer(state = empdata_json, action){
case "ADD_NEW_EMP": case "ADD_NEW_EMP":
let empdata = [...state,action.payload]; let empdata = [...state,action.payload];
return empdata; return empdata;
case "DEL_EMP":
let storedata = [...state];
let pos = action.index;
console.log("index before splice", action.index);
storedata.splice(pos,1);
console.log("after splice",storedata);
return storedata;
default: default:
return state; return state;
} }
@@ -1,10 +1,16 @@
import React,{Component} from 'react'; import React,{Component} from 'react';
import {connect } from 'react-redux'; import {connect } from 'react-redux';

import {bindActionCreators} from 'redux';
// import empdata from '../data/employeedata.json'; import {delEmp} from '../allactions';


class FormdataTable extends Component { class FormdataTable extends Component {
state = { } state = { }
handleDelete(index){
this.props.delEmp(index);
}
handleEdit(index){
console.log("Edit:",index);
}
render() { render() {
console.log(this.props.empdata); console.log(this.props.empdata);
return ( return (
@@ -61,5 +67,7 @@ function mapStateToProps(state){
empdata : state empdata : state
}; };
} }
export default connect(mapStateToProps,null)(FormdataTable); function mapDispatchToProps(dispatch){
// export default FormdataTable; return bindActionCreators({delEmp},dispatch)
}
export default connect(mapStateToProps,mapDispatchToProps)(FormdataTable);
@@ -117,5 +117,4 @@ handleSubmit(){
function mapDispatchToProps(dispatch){ function mapDispatchToProps(dispatch){
return bindActionCreators({addNewEmp},dispatch) return bindActionCreators({addNewEmp},dispatch)
} }
export default connect (null, mapDispatchToProps)(SignupForm) export default connect (null, mapDispatchToProps)(SignupForm)
// export default SignupForm;

0 comments on commit cd9712a

Please sign in to comment.
You can’t perform that action at this time.