All Projects → kMeillet → Reason Loadable

kMeillet / Reason Loadable

Licence: mit
🔥 Suspense/Lazy for ReasonReact.

Programming Languages

javascript
184084 projects - #8 most used programming language
bucklescript
41 projects

Projects that are alternatives of or similar to Reason Loadable

bs-dynamic-import
📦🚀 BuckleScript dynamic import interop on JavaScript environment
Stars: ✭ 31 (-64.77%)
Mutual labels:  dynamic, code-splitting, import, reasonml
Webpack Require From
Webpack plugin that allows to configure path or URL for fetching dynamic imports
Stars: ✭ 142 (+61.36%)
Mutual labels:  import, code-splitting, dynamic
Lazy Compile Webpack Plugin
Boost webpack startup time by lazily compiling dynamic imports
Stars: ✭ 106 (+20.45%)
Mutual labels:  dynamic, lazy
React Native Wormhole
⚛️ 🌌 Inter-dimensional Portals for React Native. 👽 🖖
Stars: ✭ 133 (+51.14%)
Mutual labels:  dynamic, component
Vue Dynamic Form Component
Vue dynamic nested form component, support nested Object/Hashmap/Array. Vue动态多级表单组件,支持嵌套对象/Hashmap/数组。
Stars: ✭ 220 (+150%)
Mutual labels:  dynamic, component
Hitchcock
The Master of Suspense 🍿
Stars: ✭ 167 (+89.77%)
Mutual labels:  lazy, component
React Echarts Modules
这个例子给你提供在react中使用echarts的最优方案
Stars: ✭ 185 (+110.23%)
Mutual labels:  import, lazy
Redux Dynamic Modules
Modularize Redux by dynamically loading reducers and middlewares.
Stars: ✭ 874 (+893.18%)
Mutual labels:  code-splitting, dynamic
React Component Library
A project skeleton to get your very own React Component Library up and running using Rollup, Typescript, SASS + Storybook
Stars: ✭ 313 (+255.68%)
Mutual labels:  code-splitting, component
Ng Dynamic Component
Dynamic components with full life-cycle support for inputs and outputs for Angular
Stars: ✭ 396 (+350%)
Mutual labels:  dynamic, component
Async Reactor
Render async Stateless Functional Components in React
Stars: ✭ 452 (+413.64%)
Mutual labels:  code-splitting, component
Hr4r
Example project - "Hot Reloading 4 RequireJS" front-end web applications & some extra code demonstrating hot-reloading for Node.js Express servers
Stars: ✭ 28 (-68.18%)
Mutual labels:  code-splitting, dynamic
React Native Swipeview
The best SwipeView component for React Native.
Stars: ✭ 81 (-7.95%)
Mutual labels:  component
Ireact
🎁 iReact: Fantastic React Components and Libraries! Makes it easy for you to pick one that’ll work for you.
Stars: ✭ 83 (-5.68%)
Mutual labels:  component
Wymaterialbutton
Interactive and fully animated Material Design button for iOS developers.
Stars: ✭ 80 (-9.09%)
Mutual labels:  component
React Router Animation Examples
An example using React Router and React's Animations
Stars: ✭ 80 (-9.09%)
Mutual labels:  code-splitting
React Places Autocomplete
React component for Google Maps Places Autocomplete
Stars: ✭ 1,265 (+1337.5%)
Mutual labels:  component
Bs Glamor
BuckleScript bindings for glamor
Stars: ✭ 83 (-5.68%)
Mutual labels:  reasonml
Percy Storybook
Percy's Storybook SDK.
Stars: ✭ 80 (-9.09%)
Mutual labels:  component
Rescript React Update
useReducer with updates and side effects!
Stars: ✭ 79 (-10.23%)
Mutual labels:  reasonml

Summary

Build Status NPM license

🔥 Suspense/Lazy for ReasonReact.

Installation

npm install reason-loadable --save

Then add "reason-loadable" in "bsconfig.json" :

"bs-dependencies": [
 "reason-loadable"
]

You can now use "ReLoadable" module.

Note : "ReLoadable" contain type definition, it doesn't add any single bit into your project.

Support

  • ReasonReact component (JSX v3). ✔️
  • Non-ReasonReact component (third-party React component or your own plain JavaScript React component). ✔️

ReasonReact JSX v2 isn't supported : Please consider migrating to JSX v3 (new ReasonReact hook components).

Example

  1. Create a ReasonReact hook component (JSX v3).
/* HelloWorld.re */
[@react.component]
let make = (~name) => <h1> (React.string("Hello world " ++ name)) </h1>;

/* Export default is necessary because React lazy function always resolve the default export. */
let default = make;
  1. Create type-safe lazy component with "ReLoadable.lazy_" and "ReLoadable.import".
/* LazyHelloWorld.re */
module type T = (module type of WithPure);

/*
  Needed for BuckleScript to not import the original component :
  See https://github.com/BuckleScript/bucklescript/issues/3543
*/
let unsafePlaceholder: module T = [%raw {|{}|}];

module UnsafePlaceholder = (val unsafePlaceholder);

let makeProps = UnsafePlaceholder.makeProps;

let make =
  ReLoadable.lazy_(() => ReLoadable.import(UnsafePlaceholder.make, "./HelloWord.bs.js"));
  1. Render lazy component anywhere in your ReasonReact app with "React.Suspense".
/* App.re */
[@react.component]
let make = () => {
  <React.Suspense fallback={<div> (React.string("Loading ...")) </div>}>
    <LazyHelloWorld name="Zeus" />
  </React.Suspense>;
};

More example are available in repository.

Non-ReasonReact component

  1. Create type-safe lazy component with "ReLoadable.lazy_" and "ReLoadable.import".
/* LazyButton.re */
/* You have to type non-ReasonReact component props explicitly. */
module type T = {
  [@react.component]
  let make: (~text: string) => React.element;
};

/*
  Needed for BuckleScript to not import the original component :
  See https://github.com/BuckleScript/bucklescript/issues/3543
*/
let unsafePlaceholder: module T = [%raw {|{}|}];

module UnsafePlaceholder = (val unsafePlaceholder);

let makeProps = UnsafePlaceholder.makeProps;

/* "@my-component-lib/button" should have a default export. */
let make =
  ReLoadable.lazy_(() => ReLoadable.import(UnsafePlaceholder.make, "@my-component-lib/button"));
  1. Render lazy component anywhere in your ReasonReact app with "React.Suspense".
/* App.re */
[@react.component]
let make = () => {
  <React.Suspense fallback={<div> (React.string("Loading ...")) </div>}>
    <LazyButton text="Click !" />
  </React.Suspense>;
};

Experimental SuspenseList

Concurrent mode is only available in the experimental builds of React. To install them, run :

npm install [email protected] [email protected]

There are no semantic versioning guarantees for the experimental builds. APIs may be added, changed, or removed with any @experimental release.

Experimental releases will have frequent breaking changes.

You can try these builds on personal projects or in a branch, but we don’t recommend running them in production.

Sometime, there's breaking change in experimental builds. For example, "createRoot" function has been changed to "unstable_createRoot" recently.

Be prepared to do some research into ReasonReact and React source code if something goes wrong, especially when binding between ReasonReact and React doesn't match due to breaking changes.

Experimental ReasonReact API is available under the "Experimental" module : https://github.com/reasonml/reason-react/blob/master/src/ReactDOMRe.re#L40

Some React experimental builds can break the SuspenseList API.

Here is one experimental build that seem to work well with SuspenseList API : 0.0.0-experimental-aae83a4b9.

npm install [email protected] [email protected]
/* App.re */
/* LazyButton and LazyHelloWorld are lazy components (see previous examples). */
[@react.component]
let make = () => {
  <React.SuspenseList>
    <React.Suspense fallback={<div> (React.string("Loading ...")) </div>}>
      <LazyButton text="Click !" />
    </React.Suspense>
    <React.Suspense fallback={<div> (React.string("Loading ...")) </div>}>
      <LazyHelloWorld name="Zeus" />
    </React.Suspense>
  </React.SuspenseList>;
};
/* index.re */
/* You have to use the experimental createRoot API explicitly. */
let _ =
  switch (ReactDOMRe.Experimental.createRootWithId("root")) {
  | Ok(root) => ReactDOMRe.Experimental.render(root, <App />)
  | Error(err) => Js.log(err)
  };

API

ReLoadable.import: (Js.t('a) => React.element), string) => Js.Promise.t(Js.t('a) => React.element)

Dynamic import React component.

ReLoadable.lazy_: (unit => Js.Promise.t('a)) => 'a

React.lazy binding.

Special thanks to

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].