3 ms·
Nice simplification of the “clever” code. Lodash docs for anyone curious: https://lodash.com/docs/4.17.15#pickBy https://lodash.com/docs/4.17.15#pickBy Here’s
by roryokane 3y ago
Nice simplification of the “clever” code. Lodash docs for anyone curious: https://lodash.com/docs/4.17.15#pickBy https://lodash.com/docs/4.17.15#pickBy
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)
);
};