the other default fields of component here and override a few */
...component,
initialState: () => {count: 0, show: true},
/* State transitions */
reducer: (action, state) =>
switch (action) {
| Click => ReasonReact.Update({...state, count: state.count + 1})
| Toggle => ReasonReact.Update({...state, show: ! state.show})
},
render: self => {
let message =
"You've clicked this " ++ string_of_int(self.state.count) ++ " times(s)";
<div>
<button onClick=(_event => self.send(Click))>
(ReasonReact.stringToElement(message))
</button>
<button onClick=(_event => self.send(Toggle))>
(ReasonReact.stringToElement("Toggle greeting"))
</button>
(
self.state.show ?
ReasonReact.stringToElement(greeting) : ReasonReact.nullElement
)
</div>;
},
};
извращуга
Обсуждают сегодня