List of helpful shortcuts for faster coding
If you have any other helpful shortcuts, feel free to add in the comments of this gist :)
// state reducer | |
// 💯 default state reducer | |
import * as React from 'react' | |
import {Switch} from '../switch' | |
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args)) | |
function toggleReducer(state, {type, initialState}) { | |
switch (type) { |
// Prop Collections and Getters | |
// 💯 prop getters | |
import * as React from 'react' | |
import {Switch} from '../switch' | |
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args)) | |
function useToggle() { | |
const [on, setOn] = React.useState(false) |
// Flexible Compound Components with context | |
// 💯 custom hook validation | |
import * as React from 'react' | |
import {Switch} from '../switch' | |
const ToggleContext = React.createContext() | |
ToggleContext.displayName = 'ToggleContext' | |
function Toggle({children}) { |
import * as React from 'react' | |
/** | |
* | |
* @param {String} key The key to set in localStorage for this value | |
* @param {Object} defaultValue The value to use if it is not already in localStorage | |
* @param {{serialize: Function, deserialize: Function}} options The serialize and deserialize functions to use (defaults to JSON.stringify and JSON.parse respectively) | |
*/ | |
function useLocalStorageState( |
// Compound Components | |
// 💯 Support non-toggle children | |
// http://localhost:3000/isolated/final/02.extra-1.js | |
import * as React from 'react' | |
import {Switch} from '../switch' | |
function Toggle({children}) { | |
const [on, setOn] = React.useState(false) | |
const toggle = () => setOn(!on) |
function asyncReducer(state, action) { | |
switch (action.type) { | |
case 'pending': { | |
return {status: 'pending', data: null, error: null} | |
} | |
case 'resolved': { | |
return {status: 'resolved', data: action.data, error: null} | |
} | |
case 'rejected': { | |
return {status: 'rejected', data: null, error: action.error} |
RUN apt update | |
RUN apt upgrade -y | |
RUN apt install -y apt-utils | |
RUN a2enmod rewrite | |
RUN apt install -y libmcrypt-dev | |
RUN docker-php-ext-install mcrypt | |
RUN apt install -y libicu-dev | |
RUN docker-php-ext-install -j$(nproc) intl | |
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng12-dev | |
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ |
/* font size & line height in px */ | |
$font-size-body-px: 14; | |
$line-height-px: 21; | |
/* calculate font-size (in %) and line-height (in em) */ | |
$font-size-body: pc($font-size-body-px, 16); | |
$line-height: em($line-height-px, $font-size-body-px); |