Hi all
I have the following component:
type state = {value: string};
type action =
| OnKeyUp(int, string);
let allowedKeyCode = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57];
let component = ReasonReact.reducerComponent("NumberInput");
let make = (~name: string, ~value: string => unit, ~maxLength: int, _children) => {
...component,
initialState: () => {value: ""},
reducer: (action, state: state) =>
switch (action) {
| OnKeyUp(keyCode, key) =>
List.mem(keyCode, allowedKeyCode) ?
ReasonReact.UpdateWithSideEffects(
{value: state.value ++ key},
(self => value(self.state.value)),
) :
ReasonReact.NoUpdate
},
render: self =>
<input
type_="text"
maxLength=maxLength
name
value=self.state.value
onKeyUp=(
event =>
self.send(
OnKeyUp(
ReactEventRe.Keyboard.keyCode(event),
ReactEventRe.Keyboard.key(event),
),
)
)
/>,
};
I use it like:
<NumberInput name="amount" value=(v => self.send(AddAmount(int_of_string(v)))) maxLength=5/>
maxLength
does not work at all why?
Thanks