Hi all
I wrote a component, that should only accept numbers:
type state = {inputValue: string};
type action =
| OnKeyPress(string);
let component = ReasonReact.reducerComponent("NumberInput");
let make = (value: string, _children) => {
...component,
initialState: () => "",
reducer: (action, _state) =>
switch (action) {
| OnKeyPress(v) =>
UtilWrapper.acceptOnlyNumbers(v) ?
ReasonReact.UpdateWithSideEffects(
{inputValue: v},
(
self => {
value = self.state.inputValue;
();
}
),
) :
ReasonReact.NoUpdate
},
render: self =>
<input
type_="text"
value=self.state.inputValue
onKeyPress=(
event =>
self.send(
OnKeyPress(
ReactDOMRe.domElementToObj(ReactEventRe.Keyboard.target(event))##value,
),
)
)
/>,
};
and the compiler complains:
We've found a bug for you!
/home/developer/Desktop/reason-react/cockpit/src/Input/NumberInput.re 19:15-43
17 ┆ (
18 ┆ self => {
19 ┆ value = self.state.inputValue;
20 ┆ ();
21 ┆ }
The value value is not an instance variable
ninja: build stopped: subcommand failed.
>>>> Finish compiling(exit: 1)
What am I doing wrong?
Thanks