2017-02-19 2 views
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는 다음과 I

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);

내 작업은

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

+0

당신은 redux로'Note' 구성 요소를 연결하지 않습니다. –

+0

또한 dispatch()를 통해 작업을 전달하지 않았습니다. – macbem

+0

나는 요소에 기능을 전파하고 있지만 읽을 수없는 것으로 렌더링 할 래퍼 컴포넌트가 3 개있다. dispatch @macbem을 통해 무엇을 의미합니까? 나는 function mapDispatchToProps (dispatch) { return { 액션 : bindActionCreators (액션, 디스패치) }}; } 내 주요 구성 요소 –

답변

2

여기에 시도하는 몇 가지 있습니다. 프로젝트에서

  • configureStore.js"../rootReducer"에서 rootReducer을 수입하지만, 이러한 모듈은 없다. 이게 일지는 확실하지 않지만 확인해 볼 가치가 있습니다.

  • Dispatch 할 인수는 작업이어야합니다. actions.toggleNoteValue 은 작업이 아니며 작업을 반환하는 함수입니다. 대신
    props.store.dispatch(actions.toggleNoteValue()) 또는
    props.actions.toggleNoteValue()을 사용해보십시오.

관련 문제