diff options
Diffstat (limited to 'bs5/universal/native/shared/ServerActionWithSimpleResponse.re')
-rw-r--r-- | bs5/universal/native/shared/ServerActionWithSimpleResponse.re | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/bs5/universal/native/shared/ServerActionWithSimpleResponse.re b/bs5/universal/native/shared/ServerActionWithSimpleResponse.re new file mode 100644 index 0000000..7df593e --- /dev/null +++ b/bs5/universal/native/shared/ServerActionWithSimpleResponse.re @@ -0,0 +1,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>; +}; |