Skip to content

Instantly share code, notes, and snippets.

View alexkrolick's full-sized avatar
🎩
Open for consulting gigs!

Alex Krolick alexkrolick

🎩
Open for consulting gigs!
View GitHub Profile
@alexkrolick
alexkrolick / index.html
Created March 3, 2017 06:08
React-Quill Custom HTML Toolbar
<div class="app">
</div>
@alexkrolick
alexkrolick / index.html
Last active September 22, 2022 04:28
React-Quill Custom Format w/Parchment Demo
<div class="app">
</div>
@alexkrolick
alexkrolick / retry.js
Created August 11, 2017 17:43
Async retry utility for Node
const backoffFns = {
constant: curDelay => curDelay,
geometric: curDelay => curDelay * 2,
}
const defaultOpts = {
maxTries: 2,
delay: 0,
backoff: 'constant',
logger: console.log,
@alexkrolick
alexkrolick / script.jsx
Last active September 8, 2017 06:46
Renderless Components
/* Edit on Codepen: https://codepen.io/alexkrolick/pen/QMXMMv */
class StateContainer extends React.Component {
constructor(props) {
super(props);
}
get handlers() {
return {};
}
const InjectTimestamp = ({children, ...props}) => {
const time = new Date()
return children(time)
}
InjectTimestamp.propTypes = {
children: PropTypes.func,
}
const Foo = () => {
class Container extends Component {
state = {
text: 'foo'
}
changeText = newText => this.setState({text: newText})
render() {
<div>
<Presenter1 text={this.state.text} changeText={this.changeText} />
<Presenter2 text={this.state.text} />
<div>
// JSX
const withFooProp = WrappedComponent => props => <WrappedComponent foo={2} {...props} />
// createElement
const withFooProp = WrappedComponent => props => h(WrappedComponent, { foo: 2, ...props })
const Bar // ... a component
export default withFooProp(Bar) // export an augmented version of Bar
// elsewhere...
import React, { createElement as h } from 'react'
import { render } from 'react-dom'
const foo = h("i", {}, "Foo")
const bar = h("span", { style: "color: red;" }, "Bar", foo)
render(bar, document.body)
import React, { Component, createElement as h } from 'react'
const Foo = ({text, ...props}) => h("span", props, text)
const Bar = props => h("div", {},
h(Foo, { ...props, style: "color: blue" })
)
class Baz extends Component {
constructor(props) {
// JSX
<div className="myClass">
<Foo selected />
<Bar />
{ [1,2,3].map(i => i**2) }
</div>
// Equivalent createElement