Im receiving user Identification props from firebase and passing it as props to my Reason component, the props look like so
user: {
uid: "xxxx",
email: "xxx@gmail.com",
displayName: "name XXX"
}
The problem is I can’t read properties of the user
prop
Here’s my reason react component
type action =
| Add
| Minus;
let ste = ReasonReact.string;
type user = {. uid: string};
type account =
| None
| Accountprops(user);
[@bs.deriving abstract]
type jsProps = {
user: account,
loginFn: unit => unit,
};
let component = ReasonReact.reducerComponent("Cartcomponent");
let make = (~user, ~loginFn, _children) => {
...component,
initialState: () => 0,
reducer: (action, state) =>
switch (action) {
| Add => ReasonReact.Update(state + 1)
| Minus => ReasonReact.Update(state - 1)
},
render: self => {
let countMsg = "Count: " ++ string_of_int(self.state);
<div>
<p> (ReasonReact.string(countMsg)) </p>
<MaterialUi_Button onClick=(_event => self.send(Add))>
(ReasonReact.string("Add"))
</MaterialUi_Button>
(
switch (user) {
| None =>
<MaterialUi_Button onClick=(_event => loginFn())>
(ReasonReact.string("Sign In"))
</MaterialUi_Button>
| Accountprops(response) =>
<MaterialUi_Button onClick=(_event => Js.log(response))>
(ReasonReact.string("Buy as"))
</MaterialUi_Button>
}
)
</div>;
},
};
let default =
ReasonReact.wrapReasonForJs(~component, jsProps =>
make(~user=jsProps |. user, ~loginFn=jsProps |. loginFn, [||])
);
On clicking the button with the buy as label I get
response === undefined
This is how the component receives its props
<Cartcomponent user={safeUser} loginFn={this.handleLogin} />;
The user can either be an object or null