Commit 9f092995 authored by Natalie Marleny's avatar Natalie Marleny Committed by Tim Neutkens

fix:5049 Make Count in with-reasonml persist in runtime (#7302)

This replicates the functionality of the shared-modules example with ReasonML.
parent c21116ae
type action = let count = ref(0);
| Add;
type state = {count: int};
[@react.component] [@react.component]
let make = () => { let make = () => {
let (state, dispatch) = let (_state, dispatch) = React.useReducer(
React.useReducer( (_, _) => Js.Obj.empty(),
(state, action) => Js.Obj.empty()
switch (action) { );
| Add => {count: state.count + 1}
}, let countMsg = "Count: " ++ string_of_int(count^);
{count: 0},
);
let countMsg = "Count: " ++ string_of_int(state.count); let add = () => {
count := count^ + 1;
dispatch();
};
<div> <div>
<p> {ReasonReact.string(countMsg)} </p> <p> {ReasonReact.string(countMsg)} </p>
<button onClick={_ => dispatch(Add)}> {React.string("Add")} </button> <button onClick={_ => add()}> {React.string("Add")} </button>
</div>; </div>;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment