Skip to content

Instantly share code, notes, and snippets.

@tortillaj
tortillaj / useColumnCount.ts
Created January 28, 2019 20:32
React hook for setting column counts based on window size, useful for css grid
import { useState, useEffect, useLayoutEffect } from 'react'
interface Point {
count: number;
width: number;
}
const throttle = (throttledFunction: Function, wait: number, context: void) : any => {
let timeoutId: any = null
let callbackArgs: any[] = []
import React from 'react'
import { api } from 'ducks/user'
const MultiplePatronContext = React.createContext({
isMultiplePatronEnabled: false,
error: '',
})
export class MultiplePatronProvider extends React.Component {
import {compose, setPropTypes, defaultProps, withHandlers, componentFromProp, setDisplayName} from 'recompose'
const componentEnhance = defaultProps({ component: 'button' })
const ButtonComponent = componentEnhance(componentFromProp('component'))
const enhance = compose(
setDisplayName(`Button`),
setPropTypes({
onClick: PropTypes.func,
type: PropTypes.oneOf(['submit', 'button']),
import {compose, setPropTypes, defaultProps, withHandlers} from 'recompose'
const enhance = compose(
setPropTypes({
onClick: PropTypes.func,
type: PropTypes.oneOf(['submit', 'button']),
className: PropTypes.func,
children: PropTypes.func.isRequired,
isLoading: PropTypes.bool,
}),
import {compose, setPropTypes, defaultProps} from 'recompose'
const enhance = compose(
setPropTypes({
onClick: PropTypes.func,
type: PropTypes.oneOf(['submit', 'button']),
className: PropTypes.func,
children: PropTypes.func.isRequired,
isLoading: PropTypes.bool,
}),
export default const Button = ({ type, className, children, onClick, isLoading }) => {
return (
<button type={type} className={className} onClick={onClick}>
{isLoading && <Loading />}
{!isLoading && children}
</button>
)
}
@tortillaj
tortillaj / class-component.js
Last active January 18, 2018 19:32
React Recompose blog post
export default class Button extends React.Component {
constructor(props) {
super(props)
this.state = {
isLoading: false,
}
}
static propTypes = {
onClick: PropTypes.func,
@tortillaj
tortillaj / Development Handbook.md
Created January 8, 2018 15:04
Guidelines for friendly programming
@tortillaj
tortillaj / .block
Created April 23, 2017 21:14
fresh block
license: mit
scrolling: yes
border: no
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);