by gcmeplz · 3y ago · 0 comments
function extractDataFromResponse ([Component, props]) {
return _.pickBy({Component, props}, Boolean);
}
I'm cheating by using lodash, but I think this code is a fairer comparison to the unclever example that's given in the article.Here’s my version of the “clever” example that doesn’t depend on Lodash. It’s longer than your version but still simpler than the article’s:
const extractDataFromResponse = (response) => {
const [Component, props] = response;
const dataIncludingUndefinedValues = { Component, props };
return Object.fromEntries(
Object.entries(dataIncludingUndefinedValues).filter(([_key, val]) => val)
);
};