我正在尝试创建一个简单的待办事项应用程序,这是一个输入组件,我需要一个reducer来更新输入状态。这段代码会抛出错误 - 这个模式匹配的是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(() => "");
}
}
/>,
};