2016-11-15 1 views
0

Redux와 네이티브 응용 프로그램을 연결하고 구성 요소의 생성자에서 Redux에서 데이터를 가져 오려고합니다. 여기처리되지 않은 약속 거부 (ID : 0) : 정의되지 않음이 개체가 아닙니다.

class Accordion extends Component { 
... 

constructor (props) { 
super(props) 
this.state = { 
    activeSections: [this.props.initiallyActiveSection] 
} 

// if activeSection not specified, default to initiallyActiveSection 
let { library } = this.props 
if (library.activeSections) { //<-- here is an error library is undefined 
    this.setState({activeSections: library.activeSections}) 
} 

_toggleSection (section) { 
const activeSection = section 
    let isOpened = this.state.activeSections.indexOf(section) >= 0 ? true : false 
    var indexInActiveSections = this.state.activeSections.indexOf(section) 
if (isOpened === true) { 
     this.state.activeSections.splice(indexInActiveSections, 1) 
    } else { 
     this.state.activeSections.push(section) 
    } 

    this.props.libraryActions.setActiveSections(this.state.activeSections) 

    this.setState({ activeSection }) 
    } 

    render() { 
... 
} 

} 

    Accordion.PropTypes = { 
    library: React.PropTypes.arrayOf(React.PropTypes.number) 
} 

export default connect(state => ({ 
    library: state.library 
    }), 
    (dispatch) => ({ 
    libraryActions: bindActionCreators(libraryActions, dispatch) 
    }) 
)(Accordion) 

module.exports = Accordion 

: 정의되지 않은

여기

내 코드입니다 ('library.activeSections을'평가) 객체가 아닌 : 가능한 처리되지 않은 약속 거부 (: 0 아이디 :) 나는 다음과 같은 오류를 받고 있어요 이다 라이브러리 감속기 감속기/library.js :

export const setActiveSections = (activeSections) => { 
    return { 
    type: 'SET_ACTIVE_SECTIONS', 
    activeSections 
    } 
} 
: 여기

import { Map } from 'immutable' 

const initialState = Map({ 
    activeSections: [0] 
}) 

export default function library (state = initialState, action = {}) { 
    switch (action.type) { 
    case 'SET_ACTIVE_SECTIONS': 
     return { 
     ...state, 
     activeSections: action.activeSections 
     } 
    default: 
     return state 
    } 
} 

및 라이브러리 액션 액션/library.js입니다

여기 감속기 /하는 index.js입니다 :

import articles from './articles' 
import journal from './journal' 
import library from './library' 

export { 
    articles, 
    journal, 
    library 
} 

도와 this.props

희망에는 라이브러리 객체가없는 이유는 이해할 수 없다.

+1

를 제거 선 'module.exports = 아코디언'을 제거하고 도움이 – Jickson

+0

을 시도! 당신은 최고의 @Jickson – Dmitry

+0

당신을 도왔다. 응답을 나중에 누군가에게 도움이되도록 추가했습니다. – Jickson

답변

1

라인 module.exports = Accordion

관련 문제