react-hooks-registry

0.0.2 • Public • Published

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

Package Sidebar

Install

npm i react-hooks-registry

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

4.8 kB

Total Files

5

Last publish

Collaborators

  • cawfree