Skip to content

Instantly share code, notes, and snippets.

View dane-stevens's full-sized avatar

Dane Stevens dane-stevens

View GitHub Profile
import React from "react";
// Import State RenderProp Component
import State from "./State";
const Button = ({ children }) => (
// Wrap <Button /> with <State />
// Pass init prop to set the default state
<State init={{ disabled: false }}>
// <State />'s render function returns (function, state)
import React from "react";
class Button extends React.Component {
constructor(props) {
super(props);
this.state = {
disabled: false
};
this.handleClick = this.handleClick.bind(this);
}
import React from "react";
const Button = ({ children }) => <button>{children}</button>;
export default Button;
import React from "react";
import PropTypes from "prop-types";
// Create a State Render Prop Component
class State extends React.Component {
constructor(props) {
super(props);
// Initialize state from init prop
this.state = this.props.init;