我需要访问一个字段值以在它发生变化时触发特殊逻辑。
我能做到:
const { input: { value: myField }} = useField("myField");
// do some stuff with myField
const state = useFormState();
const myField = state.values.myField;
// do some stuff with myField
最好的方法是什么?它们并不完全等效,例如,当未定义 myField 时,useField 将返回 ''
,而 useFormState 将返回 undefined
。
答案 0 :(得分:0)
如果您只需要一个(或最多 3 个)字段的值,请使用 // Create the timer flow
val timer = (0..Int.MAX_VALUE)
.asSequence()
.asFlow()
.onEach { delay(1_000) } // specify delay
// Consume it
timer.collect {
println("bling: ${it}")
}
。
是的,useField
给你 useField()
。这是为了确保输入受到控制。