I was experimenting with making a declarative table API in ReasonReact, and ran into a lot of issues implementing it. Here’s the code for my full attempt: https://gist.github.com/AriaFallah/da4bc73e5ff448b0c5340bbd2473082a.
The goal is that instead of doing something like
<Table columns={} />
where columns is something like
[
{name: "a", cellRenderer: aRenderer},
{name: "b", cellRenderer: bRenderer},
]
Instead I would pass that config as children to the Table
component (This is me trying to copy the blueprintjs table // http://blueprintjs.com/docs/v2/#table.basic-usage API in ReasonReact.)
<Table numRows={5}>
<Column name="A" cellRenderer={aRenderer} />
<Column name="B" cellRenderer={bRenderer} />
</Table>
And it’d be the exact same as the array of objects approach as above, but instead of having a columns prop, I’d extract the info from the Column
components stored in the children prop of Table
.
The major problem was that I didn’t know how (or if it’s possible) to use ReasonReact elements as basically just transparent containers for data. I tried making my Column component a reducer component that just stored the props in its state, but that failed. So now I’m curious if that’s even possible.
Also sidenote…is there a way to get the return type of a function like in TS
i.e the ReturnType
method from here https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html? Since Reason is bad at inferring record types inside of methods like Belt.Array.map
I’d like to be able to write a type alias like type column = returntypeof Column.make
. The alternative being what I tried (which caused issues):
type t =
ReasonReact.componentSpec(
state,
state,
ReasonReact.noRetainedProps,
ReasonReact.noRetainedProps,
action,
);
TL;DR
-
Is it possible to store state (that never changes) in a ReasonReact component, and access it from a parent component?
-
Does Reason have any sort of
typeof
/returntypeof
operator? Or anything resembling TS or Flow’s advanced types? StrangelyFlow
andTS
feel like they have more powerful type systems to me…