为什么(undefined || false)表达式无法正常工作?

Dia*_*ond 0 javascript reactjs redux

动作/ index.js

export const fetchAppointment = (userId) => async dispatch =>{
const request = await axios.get(`${URL}/apis/appointments/${userId}`)
    dispatch({type :types.FETCH_APPOINTMENT, payload:request.data})
Run Code Online (Sandbox Code Playgroud)

};

减速器/ reducer_appointment.js

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

app.js

    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>;
    }
}
Run Code Online (Sandbox Code Playgroud)

问题我总是得到默认情况,虽然我得到数据或没有数据.我希望虚假案例在没有数据的情况下有效.

更新

我检查了结果,_.mapKeys返回undefined.所以我想知道并发布这篇文章!

请帮我!

Kra*_*mir 7

我猜是因为_.mapKeys总是至少返回一个空对象.所以{}即使有效载荷是你的状态也是如此undefined.