summaryrefslogtreecommitdiff
path: root/bs5/universal/native/shared/ServerActionWithSimpleResponse.re
blob: 7df593e30fca447263ae0dc9838c6101ff9e23a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[@react.client.component]
let make = () => {
  let (message, setMessage) = RR.useStateValue("");
  let (isLoading, setIsLoading) = RR.useStateValue(false);

  <div className={Cx.make([Theme.text(Theme.Color.Gray4)])}>
    <button
      className="font-mono border-2 py-1 px-2 rounded-lg bg-yellow-950 border-yellow-700 text-yellow-200 hover:bg-yellow-800"
      onClick={_ => {
        setIsLoading(true);
        ServerFunctions.simpleResponse.call(~name="Lola", ~age=20)
        |> Js.Promise.then_(response => {
             setIsLoading(false);
             setMessage(response);
             Js.Promise.resolve();
           })
        |> ignore;
      }}>
      {React.string("Click to get the server response")}
    </button>
    <div> <Text> {isLoading ? "Loading..." : message} </Text> </div>
  </div>;
};