Skip to content

Instantly share code, notes, and snippets.

@dane-stevens
Last active July 13, 2018 18:19
Show Gist options
  • Save dane-stevens/15d58e3de2d02e17daf1fe648b978034 to your computer and use it in GitHub Desktop.
Save dane-stevens/15d58e3de2d02e17daf1fe648b978034 to your computer and use it in GitHub Desktop.
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)
// disableButton function can be renamed as desired
// state will match object passed to init prop
{(disableButton, { disabled }) => (
<button
// onClick fire disableButton function and change state
onClick={() => {
disableButton({
disabled: true
});
}}
// Disable=true|false
disabled={disabled}
>
{children}
</button>
)}
</State>
);
export default Button;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment