Skip to content

Instantly share code, notes, and snippets.

@jamesmoss
Last active February 20, 2019 14:16
Show Gist options
  • Save jamesmoss/c52abcbb12b35bc09883fd1ba9dfd92e to your computer and use it in GitHub Desktop.
Save jamesmoss/c52abcbb12b35bc09883fd1ba9dfd92e to your computer and use it in GitHub Desktop.
import React, { useState } from 'react';
const UseHook = ({ children, hook, args }) => children(hook(...args));
<UseHook hook={ useState } args={ [0] }>
{ ({ count, setCount }) => (
<button type="button" onClick={ () => setCount(count + 1) }>I have been clicked { count } times</button>
) }
</UseHook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment