행동 /하는 index.js왜 (undefined || false) 표현식이 제대로 작동하지 않았습니까?
export const fetchAppointment = (userId) => async dispatch =>{
const request = await axios.get(`${URL}/apis/appointments/${userId}`)
dispatch({type :types.FETCH_APPOINTMENT, payload:request.data})
};
감속기/
import _ from 'lodash';
import * as types from '../actions/types';
export default function(state = null, action) {
switch (action.type) {
case types.FETCH_APPOINTMENT:
return _.mapKeys(action.payload, 'patients_id') || false
default:
return state;
}
}
내가 데이터 또는 전혀 데이터를 얻을 수 있지만 난 항상 기본 경우를 얻을 수
renderAppointment(){
console.log(this.props.appointment)
switch(this.props.appointment){
case null:
console.log("null case")
return;
case false:
console.log("false case")
return <div>false case</div>;
default:
console.log("default case")
return <div>default case </div>;
}
}
porblem을 app.js reducer_appointment.js. 데이터가 없을 때 거짓 사례가 작동되기를 바랍니다.
업데이트 내가 결과를 확인
는 _.mapKeys는 undefined를 반환합니다. 그래서 나는이 게시물을 궁금해하고 게시했습니다!
도와주세요!
'mapKeys'는 무엇을 반환합니까?/@Krasimir에서 답을보세요 –
@ palaѕn 나는 위에서 언급 한 기본 상태 결과를 얻었습니다. 데이터가 반환되지 않으면 – Diamond
은 정의되지 않거나 데이터가 반환되면 약속합니다. 괜찮습니까? – Diamond