Skip to content

Instantly share code, notes, and snippets.

View ronnycoding's full-sized avatar
🇻🇪
The only way to do great work is to love what you do.

Ronny Freites ronnycoding

🇻🇪
The only way to do great work is to love what you do.
View GitHub Profile
@ronnycoding
ronnycoding / tmux-cheat-sheet.md
Created December 31, 2021 16:19 — forked from michaellihs/tmux-cheat-sheet.md
tmux Cheat Sheet
@ronnycoding
ronnycoding / CompoundComponents.js
Last active July 20, 2022 09:11
React Patterns
// 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)
@ronnycoding
ronnycoding / _config.scss
Created August 21, 2020 02:56 — forked from michsch/_config.scss
Font size configuration with Sass (SCSS)
/* 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);
@ronnycoding
ronnycoding / useAsync.js
Last active May 10, 2022 00:59
Epic React hooks
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}
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(
@ronnycoding
ronnycoding / FlexibleCompoundComponent.js
Created July 9, 2021 04:53
Flexible Compound Components with context
// 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}) {
@ronnycoding
ronnycoding / PropGetters.js
Created July 9, 2021 04:55
Prop Collections and Getters
// 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)
@ronnycoding
ronnycoding / ControlProps4.js
Created July 9, 2021 05:01
React Patterns
// Control Props
// 💯 don't warn in production
import * as React from 'react'
import warning from 'warning'
import {Switch} from '../switch'
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args))
const actionTypes = {
@ronnycoding
ronnycoding / ControlProps.js
Created July 9, 2021 04:59
React Patterns
// Control Props
// 💯 add read only warning
import * as React from 'react'
import warning from 'warning'
import {Switch} from '../switch'
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args))
const actionTypes = {
@ronnycoding
ronnycoding / ControlProps2.js
Created July 9, 2021 05:00
React Patterns
// Control Props
// 💯 add a controlled state warning
import * as React from 'react'
import warning from 'warning'
import {Switch} from '../switch'
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args))
const actionTypes = {