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 =
| Add;
type state = {count: int};
let count = ref(0);
[@react.component]
let make = () => {
let (state, dispatch) =
React.useReducer(
(state, action) =>
switch (action) {
| Add => {count: state.count + 1}
},
{count: 0},
);
let (_state, dispatch) = React.useReducer(
(_, _) => Js.Obj.empty(),
Js.Obj.empty()
);
let countMsg = "Count: " ++ string_of_int(count^);
let countMsg = "Count: " ++ string_of_int(state.count);
let add = () => {
count := count^ + 1;
dispatch();
};
<div>
<p> {ReasonReact.string(countMsg)} </p>
<button onClick={_ => dispatch(Add)}> {React.string("Add")} </button>
<button onClick={_ => add()}> {React.string("Add")} </button>
</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