我正在尝试创建一个简单的待办事项应用程序,这是一个输入组件,我需要一个减速器来更新输入的状态。此代码引发错误 -This pattern matches values of type action but a pattern was expected which matches values of type unit => string
出于某种原因,它期望action
如此unit => string
,我不知道为什么。任何人都可以帮忙吗?
type state = string;
type action =
| InputChange(string);
let component = ReasonReact.reducerComponent("Input");
let make = (~onSubmit, _children) => {
...component,
initialState: () => "",
reducer: action =>
switch (action) {
| InputChange(text) => ReasonReact.Update(text)
},
render: ({state: todo, send}) =>
<input
className="input"
value=todo
type_="text"
placeholder="What do you want todo"
onChange={e => send(ReactEvent.Form.target(e)##value)}
onKeyDown={
e =>
if (ReactEvent.Keyboard.key(e) == "Enter") {
onSubmit(todo);
send(() => "");
}
}
/>,
};