can use | components | enhancers | screen | state | styles | utils |
---|---|---|---|---|---|---|
components | ✅ | ✅ | ✅ | 🚫 | 🚫 | 🚫 |
enhancers | 🚫 | ✅ | ✅ | 🚫 | 🚫 | 🚫 |
screen | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | 🚫 |
state | 🚫 | ✅ | ✅ | ✅ | 🚫 | 🚫 |
styles | ✅ | ✅ | ✅ | 🚫 | ✅ | 🚫 |
utils | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const mergeRefs = (...refs) => (value) => { | |
for (let i = 0; i < refs.length; i += 1) { | |
const ref = refs[i]; | |
if (typeof ref === 'function') { | |
ref(value); | |
} else if (ref) { | |
ref.current = value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const typeOf = (value: unknown | unknown[]): string => | |
({}.toString | |
.call(value) | |
.match(/\s([a-zA-Z]+)/)[1] | |
.toLowerCase()); | |
export default typeOf; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const typeOf = (value) => | |
({}.toString | |
.call(value) | |
.match(/\s([a-zA-Z]+)/)[1] | |
.toLowerCase()); | |
export default typeOf; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typeOf from './type-of'; | |
const shallowCompare: (source: Record<string, unknown | unknown[]>, target: Record<string, unknown | unknown[]>): boolean => { | |
if (typeOf(source) !== typeOf(target)) { | |
return false; | |
} | |
return Object.keys(source).every((key) => { | |
if (typeOf(source[key]) !== typeOf(target[key])) { | |
return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** BAD, BLOCKS THE EXECUTION */ | |
async function getOptions() { | |
// request "toppings" and wait for the response | |
// only then goes to the next line | |
const toppings = await getToppings(); | |
const condiments = await getCondiments(); | |
const buns = await getBuns(); | |
return { toppings, condiments, buns }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const species = ['octopus', 'squid', 'shark', 'seahorse', 'starfish', 'whale',]; | |
// TRADITIONAL WAY | |
const firstItem = species[0]; | |
const lastItem = species[species.length - 1]; | |
// NEW WAY WITH SMART ACCESS | |
const { 0: firstItem, [species.length / 2]: middleItem, [species.length - 1]: lastItem } = species; | |
console.log(firstItem, middleItem, lastItem); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typeOf from './type-of'; | |
const shallowCompare = (source: unknown | unknown[], target: unknown | unknown[]): boolean => { | |
if (typeOf(source) !== typeOf(target)) { | |
return false; | |
} | |
if (typeOf(source) === 'array') { | |
return (source as unknown[]).length === (target as unknown[]).length; | |
} else if (typeOf(source) === 'object') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typeOf from './type-of'; | |
const shallowCompare = (source, target) => { | |
if (typeOf(source) !== typeOf(target)) { | |
return false; | |
} | |
if (typeOf(source) === 'array') { | |
return source.length === target.length; | |
} else if (typeOf(source) === 'object') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const deepCompare = (source: unknown | unknown[], target: unknown | unknown[]): boolean => { | |
if (typeOf(source) !== typeOf(target)) { | |
return false; | |
} | |
if (typeOf(source) === 'array') { | |
if ((source as unknown[]).length !== (target as unknown[]).length) { | |
return false; | |
} | |