2017-02-06 7 views
0

が要求this.props機能(reactjs)

class ArchOrDlt extends Component{ 
    constructor(props) { 
     super(props) 
    } 

    deleteItem(itemId, e) { 
     console.log(itemId); 
     this.props.test(); 
     this.props.DeleteListProfileItem(itemId); 

    } 
    ArchOrDlt() { 

     const isdel = this.props.isdel; 
     const itemId = this.props.itemId; 
     if (isdel == 1) { 
     return (<div><a onClick={this.deleteItem.bind(this, itemId)} >delete</a></div>); 
     } 
     return (<div>archived</div>); 
    } 
    render() { 
     return (
     <div> 
     {this.ArchOrDlt()} 
     </div> 
    ); 
    } 

    } 

によって要素を削除するコードを持って、私はリンクを押すと、私がキャッチされない例外TypeErrorを得ることではありませんそこで私は小道具

に派遣
const mapDispatchToProps = function(dispatch) { 
    return { 
     IncomeListProfile:() => dispatch(IncomeProfileList()), 
     DeleteListProfileItem: (id) => dispatch(DeleteListProfileItem(id)), 
     openPopUp:() => dispatch(openPopUp()), 
     test:() => dispatch(test()) 
     } 
    } 
私が移動した場合、それは)this.props.test(exapleために起こりますなぜ

を理解することはできません。別のクリック、正常に動作し、そこに完全なコンポーネント https://plnkr.co/edit/OEugCIxoAGE8iVb57WOa?p=catalogue

答えて

0

まずすべてに、あなたはReduxの

import { bindActionCreators } from 'redux'; 
... 
const mapDispatchToProps = (dispatch) => { 
    return { 
    IncomeListProfile : bindActionCreators(IncomeProfileList, dispatch), 
    ... 
    } 
} 

http://redux.js.org/docs/api/bindActionCreators.html

からbindActionCreators機能を使用する必要があります
関連する問題