GithubHelp home page GithubHelp logo

bs-react's Introduction

BsReact

npm install --save bs-react

What?

BsReact is a fork of ReasonReact adapted to work with Hooks and Context.

Reason React uses the good old createClass under the hood. BsReact has a simplified api that converts components defined in Reason to plain function components, allowing hooks to be used.

Why?

We all want to use all the shiny new things from React in Reason. With Hooks, there's no need for anything other than function components, so it makes sense to have a more minimal set of React bindings for Reason.

API

The api is similar to ReasonReact, but there's only one type of component, and you can only define a render function.

Example:

module Counter = {
  let component = ReasonReact.component("Counter");

  let make = (~initial=0, _children) => {
    ...component,
    render: _self => {
      let (count, setCount) = ReactHooks.useState(initial);
      <div>
        {ReasonReact.string(string_of_int(count))}
        <button onClick={_ => setCount(. count + 1)}>
          {ReasonReact.string("Click me")}
        </button>
      </div>;
    },
  };
};

For more details, check out the source. Better docs are coming.

Status

Early experimentation. Only for the brave.

Future

The plan is to support all functionality from React 16/17.

  • Suspense
  • React.lazy
  • React.pure
  • React Native
  • etc

I hope some of these things will make it into ReasonReact in some form.

Later on, making this work with ReactMini or some other pure Reason implementation of React would be cool.

Let's chat on Discord!

Contributions

More than welcome!

Thanks

Hooks and Context types are copied from Jared Forsyth.

bs-react's People

Contributors

eldh avatar jjt avatar

Watchers

Leandro Ostera avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.