2017-03-03 5 views
1

bindActionCreatorsを使用してアクションをディスパッチしていますが、空のオブジェクトが取得されています。 私は次のコードしているbindActionCreatorsが空のオブジェクトを返す - Redux

主なコンポーネントの1以下の

import React from 'react'; 
import { bindActionCreators } from 'redux'; 
import { connect } from 'react-redux'; 
import {Row, Form, FormGroup, FormControl, Button, Col} from 'react- bootstrap'; 
import * as RegisterActions from 'actions/betaPageActions'; 

export default class LoginForm extends React.Component { 
constructor(props) { 
    super(props); 
    let { register, dispatch } = this.props; 
    this.state = register; 
    this.actions = bindActionCreators(RegisterActions, dispatch); 
} 

handleChange(item, e) { 
    const change = this.props.register; 
    change[item] = e.target.value; 
    console.log("change", change); 
    this.actions.handlechanges(change); 
} 

render() { 
return (
    <Row> 
     <Col md={12}> 
      <Form inline className="login-beta"> 
       <FormGroup controlId="formControlsSelect"> 

       <FormControl componentClass="select" placeholder="I am.." 
       onChange={this.handleChange.bind(this, 'type')}> 
        <option value="">I am..</option> 
        <option value="startup">Startup</option> 
        <option value="investment_company">Investment Company/Group</option> 
        <option value="surfer">Individual Investor/Surfer</option> 
       </FormControl> 
       </FormGroup> 
       {' '} 
       <FormGroup controlId="formInlineEmail"> 

       {' '} 
       <FormControl type="email" placeholder="Email address" 
       onChange={this.handleChange.bind(this, 'email')}/> 
       </FormGroup> 
       {' '} 
       <Button type="submit"> 
       I'M IN! 
       </Button> 
      </Form> 

     </Col> 
    </Row> 


); 
} 
} 

function mapStateToProps(state) { 
const { register } = state; 
return { 
    register 
}; 
} 

LoginForm.propTypes = { 
register: React.PropTypes.object, 
dispatch: React.PropTypes.func.isRequired 
}; 

export default connect(mapStateToProps)(LoginForm); 

アクション・ファイルである

アクション

import * as types from 'constants'; 
import api from 'utils/api/beta'; 

export function handleChanges(changes) { 
    return { 
    type: types.HANDLEREGISTERATTR, 
    payload: { 
    changes 
    } 
    } 
} 

RegisterActionsを記録するとhandleChanges関数が見えますが、bindActionCreators(RegisterActions、dispatch)を使用すると空のオブジェクトができます。何か不足していますか?あなたの行動のクリエイターを取り、派遣

mapDispatchToProps = (dispatch) => (bindActionCreators ({ 
    RegisterActions : RegisterActions 
},dispatch) 

//connect should be changed to 
connect(mapStateToProps, mapDispatchToProps)(LoginForm); 

とそれらを結合すること、別のmapDispatchToPropsを宣言する必要が

+1

あなた自身でディスパッチするアクションをバインドする必要はありません。 'RegisterActions'を' connect(mapStateToProps、RegisterActions)(LoginForm) 'のように渡してください。 'this.props.somebindedAction'を使います。 –

答えて

0

は、その後、あなたのpropsであなたはReduxのアクション

this.props.RegisterActions()

を派遣する機能 RegisterActionsを持っています
関連する問題