给定以下类型:
type ('props,'state) reactInstance =
{
props: 'props;
state: 'state;
updater:
'event .
(('props,'state) reactInstance -> 'event -> 'state) ->
('props,'state) reactInstance -> 'event -> unit;}
Run Code Online (Sandbox Code Playgroud)
我正在努力实现:
let rec updater f instance event =
let nextState = f instance event in
let newInstance =
{ props; state = nextState; updater } in
()
let newInstance =
{ props; state = (reactClass.getInitialState ()); updater }
Run Code Online (Sandbox Code Playgroud)
我给了更新程序一个类似 forall 的类型定义。我的主要动机是因为更新程序将被事件调用。事先不知道该事件会是什么。它可以是用户界面上的点击或按键等。
updater定义中出现的问题{ props; state = nextState; **updater** }:
Error: This field …Run Code Online (Sandbox Code Playgroud)