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
<div class="app"> | |
</div> |
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
<div class="app"> | |
</div> |
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 backoffFns = { | |
constant: curDelay => curDelay, | |
geometric: curDelay => curDelay * 2, | |
} | |
const defaultOpts = { | |
maxTries: 2, | |
delay: 0, | |
backoff: 'constant', | |
logger: console.log, |
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
/* Edit on Codepen: https://codepen.io/alexkrolick/pen/QMXMMv */ | |
class StateContainer extends React.Component { | |
constructor(props) { | |
super(props); | |
} | |
get handlers() { | |
return {}; | |
} |
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 InjectTimestamp = ({children, ...props}) => { | |
const time = new Date() | |
return children(time) | |
} | |
InjectTimestamp.propTypes = { | |
children: PropTypes.func, | |
} | |
const Foo = () => { |
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
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> |
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
// 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... |
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, { 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) |
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, { 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) { |
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
// JSX | |
<div className="myClass"> | |
<Foo selected /> | |
<Bar /> | |
{ [1,2,3].map(i => i**2) } | |
</div> | |
// Equivalent createElement |