Skip to content

Easy way to simplify pages, and satisfy FastRefresh #47

@mathieutu

Description

@mathieutu

Hi @ryyppy,
Rescript beginner here, I'm digging around nextjs with rescript.
I've seen in all your pages that you can't re-export directly the default, because of fast refresh and the name $$default of the components.

However, if we use the @react.component decorator, the name will not be only default but MyModule$default which totaly satitisfy FastRefresh:

module Label = {
  @react.component
  let make = (~title: string) => {
    <div className="myLabel"> {React.string(title ++ "foo")} </div>
  }
}

@react.component
let default = () => {
  <div>
    <Label title="Getting Started" />
    {React.string("foo")}
  </div>
}

⇣⇣⇣

// Generated by ReScript, PLEASE EDIT WITH CARE

import * as React from "react";

function MyTest$Label(Props) {
  var title = Props.title;
  return React.createElement("div", {
              className: "myLabel"
            }, title + "foo");
}

var Label = {
  make: MyTest$Label
};

function MyTest$default(Props) {
  return React.createElement("div", undefined, React.createElement(MyTest$Label, {
                  title: "Getting Started"
                }), "foo");
}

var $$default = MyTest$default;

export {
  Label ,
  $$default ,
  $$default as default,
  
}
/* react Not a pure module */

My next page is here only:

export { default } from 'modules/MyTest.bs.js'

So why not use the decorator on the default component?

Thanks.
Mathieu.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions