0
나는 까다로운 상황에 선다. 이 RhythmContainer.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;
}
}
구성 요소 :
내 감속기 rhythmReducer.js는 다음과 Iimport 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);
내 작업은
import * as types from '../constants/actionTypes';
export function toggleNoteValue() {
console.log("toggleNoteValue");
return {type: types.TOGGLE_NOTE_VALUE};
}
rhythmActions.js
에 정의 된 경우에도 페이지가 내가 사업부를 클릭 할 때 실행 얻을 수없는 초기화 할 때 감속기 실행하지만. toggleNoteValue()가 실행 중이지만 실제 감속기에는 절대 들어 가지 않습니다. 도움이 되었습니까? 전체 프로젝트가 그냥 도움이 경우 여기PS : https://github.com/ichionid/rhythmGeneratorReact/tree/master/src
당신은 redux로'Note' 구성 요소를 연결하지 않습니다. –
또한 dispatch()를 통해 작업을 전달하지 않았습니다. – macbem
나는 요소에 기능을 전파하고 있지만 읽을 수없는 것으로 렌더링 할 래퍼 컴포넌트가 3 개있다. dispatch @macbem을 통해 무엇을 의미합니까? 나는 function mapDispatchToProps (dispatch) { return { 액션 : bindActionCreators (액션, 디스패치) }}; } 내 주요 구성 요소 –