Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while compiling reducerComponent "Is this a ReasonReact reducerComponent or component with retained props?"

I'm getting an error when creating a reducerComponent:

Code

type state = {repoData: RepoData.repo};

let dummyRepo: RepoData.repo = {
  stargazers_count: 27,
  full_name: "jsdf/reason-react-hacker-news",
  html_url: "https://github.com/jsdf/reason-react-hacker-news"
};

let component = ReasonReact.reducerComponent("Page1");

let make = (_children) => {
  ...component,
  initialState: () => {
    repoData: dummyRepo
  },
  render: (self) => {
    <div className="App">
      <h1>{ReasonReact.stringToElement("Reason Projects")}</h1>
      <RepoItem repo={self.state.repoData} />
    </div>
  }
};

Error:

Failed to compile.

./src/index.re
Module build failed: Error: We've found a bug for you!
  /Users/me/personal/test/reason-app-shell-starter-kit/src/page1.re 9:17-53

   7 │ };
   8 │
   9 │ let component = ReasonReact.reducerComponent("Page1");
  10 │
  11 │ let make = (_children) => {

  Is this a ReasonReact reducerComponent or component with retained props?
  If so, this error will disappear after:
  - Defining the component's `make` function
  - Using the state once or annotating it with a type where it's used (e.g. render)
  - Doing the same for action (in e.g. reducer)
  - Doing the same for retained props, if any

  Here's the original error message
  This expression's type contains type variables that can't be generalized:
  ReasonReact.componentSpec
  (state,  ReasonReact.stateless,  ReasonReact.noRetainedProps,
    ReasonReact.noRetainedProps,  '_a)

  This happens when the type system senses there's a mutation/side-effect, in combination with a polymorphic value.
  Using or annotating that value usually solves it. More info:
    at <anonymous>docaml.org/v1/en/html/imperative-programming-1.html#side-effects-and-weak-polymorphism

Can anyone see the problem?

Info

My package.json:

{
  "name": "reason-app-shell-starter-kit",
  "version": "0.1.0",
  "homepage": "https://persianturtle.github.io/reason-app-shell-starter-kit/build",
  "private": true,
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "reason-scripts": "0.8.0"
  },

  "devDependencies": {
    "bs-jest": "^0.3.2",
    "node-sass-chokidar": "0.0.3",
    "reason-react": "^0.3.2"
  }
}

sytem:

node v9.4.0
OS: osx
like image 567
Ashley Coolman Avatar asked Feb 26 '18 16:02

Ashley Coolman


1 Answers

You're missing the reducer. You can add a placeholder for it like this:

let make = (_children) => {
  ...component,

  initialState: () => { ... },
  reducer: ((), _state) => ReasonReact.NoUpdate,

  render: (self) => { ... }
};

Note that this is the third possible reason in the error message: "... the same for action (in e.g. reducer)". With the above placeholder the action will be inferred to be unit.

like image 74
glennsl Avatar answered Oct 06 '22 19:10

glennsl