2017-09-08 1 views
1

사용자가 잘못된 자격증 명으로 로그인하려고 시도 할 때 '오류 모달'로 표시됩니다. 내 nextProps.errorMsg가 정의되지 않았는지 아닌지 확인하고 있습니다. 오류 메시지가 있으면 오류 모달을 표시합니다.오류 소품을 처리하는 방법은 무엇입니까? (오류 모달은 한 번만 나타납니다.)

첫 번째 시도에서만 작동합니다. 그리고 'props.errorMsg'를 'Account를 찾을 수 없음'에서 'undefined'로 설정했을 때 componentWillReceiveProps가 호출하지 않은 것을 발견했습니다. 여기

componentWillReceiveProps(nextProps) { 
    // onAuthComplete Pass twice. so. it's 
    console.log('yo'); 

    console.log(nextProps.errorMsg); 
    if(nextProps.errorMsg) { 
     this._showModal(); <<- here 
    } 
    this.setState({isLoading:true}); 
    if (nextProps.hType==1 || nextProps.hType==2) { 
     nextProps.navigation.navigate('Feed'); 
     this.setState({ password: ''}) 
    } 
    } 

_hideModal =() => { 
    // empty error 
    this.props.emptyErrorMsg; 
    this.setState({ isModalVisible: false }); 
} 

당신은 코멘트에서 지적

export const emptyErrorMsg =() => ({ 
    type: EMPTY_ERROR_MSG 
}) 
+0

func'this.props.emptyErrorMsg'를 호출하지 않은 'typho'입니까? – Panther

+0

??? 나는 typho를 보지 않는다. 당신은 더 구체적 일 수 있습니까? –

+0

나는 react-redux를 사용하고 있으며 이미 emptyErrorMsg promise를 발송하고 있습니다. 나는 너의 대답에 대해 조금 혼란스러워. –

답변

2

내 감속기

const INITIAL_STATE = { token: null, errorMsg: undefined } 
export default function(state = INITIAL_STATE, action) { 
    case AUTH_LOGIN_FAIL: 
     return { token: null, errorMsg: `Can't Find Account` }; 
    case EMPTY_ERROR_MSG: 
     return { ...state, errorMsg: undefined} 
} 

과 행동을 내 조각입니다

this.props.emptyErrorMsg; 

this.props.emptyErrorMsg(); 

둘 다 함수 emptyErrorMsg를 실행합니다.
이것은 이 아니며입니다.

const yourFunction = this.props.emptyErrorMsg; 
yourFunction(); 
this.props.emptyErrorMsg(); 

this.props.emptyErrorMsg은 함수 자체에 대한 포인터를 반환 : 여기의 차이입니다. 실행되지 않습니다. 이 함수를 상수에 할당하고 나중에 상수를 실행할 수 있습니다 (yourFunction()).

this.props.emptyErrorMsg()이 기능을 실행합니다. 이것은 아마도 _hideModal() 함수에서 수행하고자하는 작업 일 것입니다.