私は微妙な状況に立っています。減速機が発射しない
私は減速rhythmReducer.jsは、以下である:
import {TOGGLE_NOTE_VALUE} from '../constants/actionTypes';
import objectAssign from 'object-assign';
import initialState from './initialState';
export default function rhythmReducer(state = initialState.rhythm, action) {
let newState = objectAssign({}, state);
console.log("---RhythmReducer");
console.log(action.type);
switch (action.type) {
case TOGGLE_NOTE_VALUE:
console.log("TOGGLE_NOTE_VALUE");
return newState;
default:
return newState;
}
}
それを使用して、コンポーネントがRhythmContainer.jsある:
import React, {PropTypes} from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import * as actions from '../actions/rhythmActions';
import {Meter} from './Meter';
export const RhythmContainer = (props) => {
let rows = [];
for (let i=0; i < props.rhythm.meters.length; i++) {
rows.push(<Meter key={i} actions={actions} rhythm= {props.rhythm.meters[i]}/>);
}
const handleClick =() => {
return props.store.dispatch(actions.toggleNoteValue);
};
return (
<div onClick={handleClick}>
This will be a 4/4 rhythm
{rows}
</div>
);
};
RhythmContainer.propTypes = {
rhythm: PropTypes.object.isRequired,
store: PropTypes.object.isRequired,
};
function mapStateToProps(state) {
return {
rhythm: state.rhythm,
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(actions, dispatch)
};
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(RhythmContainer)。
私のアクションは、ページが、私はdiv要素をクリックしたとき、私はそれを実行するために得ることができない、初期化されたときに減速が実行されるにもかかわらず
import * as types from '../constants/actionTypes';
export function toggleNoteValue() {
console.log("toggleNoteValue");
return {type: types.TOGGLE_NOTE_VALUE};
}
rhythmActions.js
で定義されています。 toggleNoteValue()が起動していますが、実際のReducerには入りません。 ヘルプがありますか?完全なプロジェクトはちょうどそれが助け場合はここにあるPS:https://github.com/ichionid/rhythmGeneratorReact/tree/master/src
あなたはreduxで 'Note'コンポーネントを接続していません。 –
また、あなたはdispatch()によってアクションをディスパッチしませんでした。 – macbem
私は要素に関数を伝播していますが、ポストを読むことができないようにする3つのラッパーコンポーネントがあります。あなたはディスパッチ@macbemを介してどういう意味ですか?私はfunction mapDispatchToProps(dispatch){ return { アクション:bindActionCreators(アクション、ディスパッチ) }}を持っています。 }私の主なコンポーネント –