render-props-opener

0.0.1 • Public • Published

render-props-opener

Basically async/await but for render propsy React components

I'll keep it brief

  • It's experimental
  • There are exactly 0 tests (yet)
  • Never measured, but it may be kinda slow
  • I'm still not content about the name
  • It can do this:
import Opener from "render-props-opener";

const LightTheme = React.createContext({
  textColor: "black",
  backgroundColor: "white"
});

const DarkTheme = React.createContext({
  textColor: "white",
  backgroundColor: "black"
});

const Mode = React.createContext("dark");

<Opener>
  {open => {
    const mode = open(<Mode.Consumer />);
    const theme =
      mode === "light"
        ? open(<LightTheme.Consumer />)
        : open(<DarkTheme.Consumer />);

    return (
      <div
        style={{
          backgroundColor: theme.backgroundColor
        }}
      >
        <h1 style={{ color: theme.textColor }}>
          I sneezed on the beat and the beat got sicker
        </h1>
      </div>
    );
  }}
</Opener>;

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i render-props-opener

    Weekly Downloads

    2

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    7.34 kB

    Total Files

    4

    Last publish

    Collaborators

    • dsblv