2017-11-26 18 views
0

나는 React with Redux을 사용하고 있으며이 문제가 있습니다.React-Redux - 하위 구성 요소의 작업을 어떻게 처리합니까?

EditorContainer.jsx을 : EditorContainer.jsx 내

<Provider store={store}> <Editor></Editor> </Provider>

파견 행동이 잘 작동

먼저 나는 store을 소개하고 렌더링 EditorContainer 구성 요소를 만드는거야.

하지만 내 Editor.jsx에서 일부 작업을 파견 할도 그래서 수행

Editor.jsx

class Editor extends React.Component { 
    componentWillMount() { 
    store.dispatch(doSomething()); 
    } 

    render() { 
    return (
     // code 
    ); 
    } 
} 

const mapStateToProps = state => ({ 
    somethingPayload: somethingPayload 
}); 

export default connect(mapStateToProps)(Editor); 

물론 내가 catch되지 않은 ReferenceError가납니다에게 : 가게입니다 정의되지 않았습니다.은 3 행에 있습니다.

connectstore & dispatch내 경우에는 구성 요소가 필요합니까?

답변

2

dispatch 기능이 소품을 통과하므로 store.dispatch 대신 this.props.dispatch을 사용해야합니다.

+0

야 ... 너와 결혼 하겠어. 그냥 물어봐. 거룩한 암소 (9 분 안에 답을 받아 들일 수 있음). 이렇게 간단하고 나는 이것에 반나절을 낭비했다, 오! : ( – Wordpressor

+0

도와 줘서 고마워요! –