2017-10-17 7 views
0

저는 원시 및 react-saga에 반응하는 새로운 방법입니다. API 호출이 작동하고 모든 것이 예상대로 작동하는 것을 볼 수 있습니다. 그러나 어떻게 서버에서 사용자에게로 돌아가는 오류를 표시 할 수 있습니까? 이것이 사소한 질문이라면 미안합니다. 여기 내 지금까지 코드사용자에게 오류를 표시하는 방법 native redux saga에 문의하십시오.

컨테이너/GetUserInfo.js가

여기
moveToJoinScreen(){ 
    this.props.getStudentAvator(vouchercode, DeviceInfo.getUniqueID(), 'iOS'); 
} 

render() { 
    return (
     <View style={styles.container}> 
     <TouchableHighlight onPress={() => this.moveToJoinScreen()} underlayColor='#ff000000'> 
      <Image style={styles.imagestyle} style={{height:60, width:150}} source={Images.joinNow} /> 
     </TouchableHighlight> 
     <Text style={styles.welcome}> 
      {'\n'} 
     </Text> 
     <TouchableHighlight onPress={() => this.moveToRegisterScreen()} underlayColor='#ff000000'> 
      <Image style={styles.imagestyle} style={{height:80, width:150}} source={Images.registerMyId} /> 
     </TouchableHighlight> 
     </View> 
    ) 
    } 
} 

const mapDispatchToProps = dispatch => ({ 
    getStudentAvator:(emailaddress, deviceid, platform) => dispatch(StudentActions.SetupVoucherRequest(vouchercode, deviceid, platform)) 
}) 

export default connect(null, mapDispatchToProps)(LaunchScreen) 

는 saga.js

내가 표시 할 컨테이너 페이지로 돌아 오류를 전달할 수있는 방법을
export function* SetupVoucherRequest(api, action) { 
    const { vouchercode, deviceid, platform } = action 
    if(vouchercode.length >11 || vouchercode.length < 10) 
    { 
     yield put(StudentCardActions.SetupVoucherFailuer()) 
     return 
    } 
    // make the call to the api 
    const response = yield call(api.SetupVoucher, vouchercode, deviceid, platform) 

    if (response.ok) { 
     const firstUser = 'fahad' 
     const avatar = 'Avatar_Fahad' 
     // do data conversion here if needed 
     yield put(StudentCardActions.SetupVoucherSuccess(avatar)) 
    } else { 
     yield put(StudentCardActions.SetupVoucherFailuer()) 
    } 
} 

확실하지입니다 오류. 어떤 도움이라도 대단히 감사하겠습니다. 사전

답변

0

감사 당신은 지금 당신이 this.props.error

+0

를 통해 UI에서 오류를 액세스 할 수있는 오류와 상태를 업데이트 한 다음 mapStateToProps

const mapStateToProps = state => ({ error: state.myStoreName.error, // depending on how your store is setup you might // have to use state.get('myStoreName').error }) export default connect(mapStateToProps, mapDispatchToProps)(LaunchScreen) 

를 통해 UI에 오류를 통과해야 put(StudentCardActions.SetupVoucherFailuer()) 전화 maStateToProps를 설정하는 방법을 읽을 수있는 곳이 있습니다. 죄송 합니다만이 모든 것을 배우려고합니다. 감사합니다 – dogwasstar

+0

@ user767018 https://egghead.io/courses/getting-started-with-redux Dan Abramov가 Redux의 발명가입니다. 'mapStateToProps'는'connect()'레슨에 있지만 처음부터 시작하는 것이 좋습니다. – FuzzyTree