Skip to content

Instantly share code, notes, and snippets.

View conorhastings's full-sized avatar
🏄‍♂️
9-5, just to make a living

Conor Hastings conorhastings

🏄‍♂️
9-5, just to make a living
View GitHub Profile
@conorhastings
conorhastings / esnextbin.md
Created May 30, 2017 19:11
esnextbin sketch
@conorhastings
conorhastings / state-component.js
Last active March 30, 2017 20:36
you can enact most of the behavior of redux with a simple component
/* 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
@conorhastings
conorhastings / esnextbin.md
Last active March 16, 2017 17:24
esnextbin sketch
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 });
});
@conorhastings
conorhastings / react-refs.js
Created January 20, 2017 03:28
react refs
/* node will be null */
function Input() {
return <input />;
}
function InputContainer() {
return <div><Input ref={node => console.log(node)} /></div>;
}
/* node will be vnode instance */
@conorhastings
conorhastings / esnextbin.md
Created October 10, 2016 19:14
esnextbin sketch
@conorhastings
conorhastings / esnextbin.md
Created August 10, 2016 12:52
esnextbin sketch
@conorhastings
conorhastings / esnextbin.md
Created July 21, 2016 13:53
esnextbin sketch
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}>
@conorhastings
conorhastings / test.js
Created November 9, 2015 05:35
Bad JSX highlighting
import React, { Component } from 'react';
class Test extends Component {
render() {
return (
<div>
Wowowow ' this is fun
</div>
);
}