0.0.2 • Published 4 years ago

react-hooks-registry v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

react-hooks-registry

Custom hooks for equally custom React renderers. Inspired by Swyx's Deep Dive on React Hooks.

Currently, React Hooks impose a dependency on the runtime version React DOM. This makes it difficult to roll hooks-based applications in the context of custom React renderers. This repository aims to make it possible to work around this restriction.

🚀 Getting Started

Using npm:

npm install --save react-hooks-registry

Using yarn:

yarn add react-hooks-registry

✍️ Usage

import React from 'react';
import ReactDOM from 'react-dom';
import HooksRegistry, { useState, useEffect } from 'react-hooks-registry';

const App = ({ ...extraProps }) => {
  const { state, setState } = useState('hello, world');
  useEffect(
    () => {
      setTimeout(
        () => setState('goodbye, world'),
        1000,
      );
    },
    [],
  );
  return (
    <div className="App">
      <code>
        {state}
      </code>
    </div>
  );
};

HooksRegistry
  .register(
    App,
    ReactDOM.render, // or use a custom renderer
    document.getElementById('root'),
  );

✌️ License

MIT