Skip to content

Instantly share code, notes, and snippets.

@scull7
Last active February 6, 2019 17:34
Show Gist options
  • Save scull7/61c88422073c7eda376fffd45f5209be to your computer and use it in GitHub Desktop.
Save scull7/61c88422073c7eda376fffd45f5209be to your computer and use it in GitHub Desktop.
module Page = {
type action =
| NoOp;
type ledger = {
id: string,
statementId: string,
actor: string,
influencer: string,
referenceType: string,
paymentId: string,
amount: string,
timestamp: int
};
type state = { items: list(ledger) };
let component = ReasonReact.reducerComponent("PageSearch");
let make = _children => {
...component,
initialState: () => { items: [] },
reducer: (action, _state: state) =>
switch (action) {
| NoOp => ReasonReact.NoUpdate
},
render: _self =>
<div>
<div className="search-bar-container">
<table className="ledger"> <TableHeader /> </table>
</div>
</div>
};
};
let render = root => ReactDOMRe.render(<Page />, root);
@scull7
Copy link
Author

scull7 commented Jan 21, 2018

I added the reducer definition, yet still receiving the same error.

  We've found a bug for you!
  /~~project-path~~/reason-react-prototype/src/TransactionList.re 56:40-47
  
  54 │ };
  55 │ 
  56 │ let render = root => ReactDOMRe.render(<Page />, root);
  
  Is this a ReasonReact reducerComponent or component with retained props?
  If so, is the type for state, retained props or action declared _after_ the component declaration?
  Moving these types above the component declaration should resolve this!
  
  Here's the original error message
  This has type:
    ReasonReact.componentSpec
    (Page.state,  Page.state,  ReasonReact.noRetainedProps, 
      ReasonReact.noRetainedProps,  Page.action)
  But somewhere wanted:
    ReasonReact.component (Page.state,  'a,  'b) (defined as
      ReasonReact.componentSpec (Page.state,  Page.state,  'a,  'a,  'b))
  The type constructor Page.state would escape its scope
  
ninja: build stopped: subcommand failed.

@scull7
Copy link
Author

scull7 commented Jan 21, 2018

Thanks to the very helpful hello123#8705 on the ReasonML discord channel, I learned that you have to annotate the state variable so that the program will compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment