Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.
/ bs-react Public archive

ReasonReact for hipsters. (Deprecated.)

Notifications You must be signed in to change notification settings

eldh/bs-react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm Blazing Fast License: MIT

BsReact

DEPRECATED!!! Use ReasonReact v0.7 instead

The easiest way to try out bs-react is with create-react-app:

npx create-react-app my-app --scripts-version=bs-react-scripts

You can also install bs-react directly:

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. Expect breaking API changes without warning.

Future

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

  • Suspense
  • React.lazy
  • React.memo
  • React Native
  • etc

See the project board for planned tasks.

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.

About

ReasonReact for hipsters. (Deprecated.)

Resources

Stars

Watchers

Forks

Packages

No packages published