Below I have an object, key-value map.
const COLORS_BY_TYPE = {
RED: 'red',
BLUE: 'blue',
GREEN: 'green',
};
const getCorrectColor = ({ colorType = 'GREEN' }) => COLORS_BY_TYPE[colorType.toUpperCase()];
I have something like the following above, it works fine when I call getCorrectColor when I don't pass the correct prop it relates to. When I pass an empty string, it doesn't work as I want. How would I modify the above so that if the prop is an empty string It would resort back to the default colour.
Could anyone provide a simple example of the type of functionality I am looking for?
COLORS_BY_TYPE[colorType.toUpperCase()] || COLORS_BY_TYPE[DEFAULT];