hello all i have a function thats called upon a websocket join, and id like to update the component state to show the room number connected to. i tried emiting an action and using ReasonReact.Update( but to no avail, can someone tell me where ive gone wrong
heres the code, i have a state and app component i hold my types and funs here then import to the app fun by open State, i can see the output in console log when i send messages down the websocket from my server.
//state.re
[@bs.module “phoenix”]
type state = {
status: string,
};
open Phx
type action =
| Add
let handleEvent = (event, response) =>
switch event {
| “test” =>
Js.log((“handleEvent:” ++ event, response))
| _ => Js.log((“handleReiceive:” ++ event))
};
let socket = initSocket("/socket") |> connectSocket |> putOnClose(() => Js.log(“Socket closed”));
let join = (channel) =>
{
let _ =
channel
|> putOn(“test”, handleEvent(“test”))
|> putOnSyncState(handleSyncState)
|> putOnsyncDiff(handleSyncDiff)
|> joinChannel
|> putReceive(“ok”, handleReiceive(“ok”))
|> putReceive(“error”, handleReiceive(“error”))
};
let channel = socket |> initChannel(“lobby”);
join(channel);
let reducer = (action, state) =>
switch(action) {
| Add=> ReasonReact.Update({…state, status: “testing”})
};
///app.re
open State;
let component = ReasonReact.reducerComponent(“App”);
let make = _children => {
…component,
initialState: () => {
status: “string”,
},
reducer,
render: ({state, send}) =>
(ReasonReact.string(“the title”))
};