made with esnextbin
This file contains 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
/* this lacks subscribe behavior or ability to dispatch from outside of component tree but that is generally not neccesary */ | |
class State extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = YOUR_INITIAL_STATE; | |
} | |
reducer = (action, state, props) => {...newState}; | |
/* setState takes an object of new state as first arg or a function of props and state that returns new state | |
* which we will use here | |
* we pass dispatch around and use it similarly to redux dispatch |
made with esnextbin
This file contains 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
function PromiseComponent(initializeComponent, loadingComponent) { | |
let cachedComponent; | |
return class PromiseComponent extends React.Component { | |
state = { Component: cachedComponent || loadingComponent || () => null }; | |
componentDidMount() { | |
if (!cachedComponent) { | |
initializeComponent.then(component => { | |
cachedComponent = component.default; | |
this.setState({ Component: cachedComponent }); | |
}); |
This file contains 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
/* node will be null */ | |
function Input() { | |
return <input />; | |
} | |
function InputContainer() { | |
return <div><Input ref={node => console.log(node)} /></div>; | |
} | |
/* node will be vnode instance */ |
made with esnextbin
made with esnextbin
made with esnextbin
This file contains 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 from 'react'; | |
import { render } from 'react-dom'; | |
import SyntaxHighlighter from 'react-syntax-highlighter'; | |
import { docco } from 'react-syntax-highlighter/dist/styles' | |
import markdown from 'markdown'; | |
class X extends React.Component { | |
render() { | |
return ( | |
<SyntaxHighlighter language='javascript' style={docco}> |
This file contains 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 } from 'react'; | |
class Test extends Component { | |
render() { | |
return ( | |
<div> | |
Wowowow ' this is fun | |
</div> | |
); | |
} |