You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
为什么不支持watch动态的路径呢?事实上我传一个动态的namePath,它似乎也能正常工作,只是代码里写了让它warnning。但如果我传了一个动态的selector,它不起效,selector会保持不变,我想是否因为这里effect没有依赖dependencies(when type is func)。所以为什么不加上这个依赖呢?然后不用ref来接受namePath,将namePath也放入依赖中,似乎这样就支持动态路径,而不必报错了。
// in useWatchuseEffect(()=>{// Skip if not exist form instanceif(!isValidForm){return;}const{ getFieldsValue, getInternalHooks }=formInstance;const{ registerWatch }=getInternalHooks(HOOK_MARK);constgetWatchValue=(values: any,allValues: any)=>{constwatchValue=options.preserve ? allValues : values;returntypeofdependencies==='function'
? dependencies(watchValue)
: getValue(watchValue,namePathRef.current);};constcancelRegister=registerWatch((values,allValues)=>{constnewValue=getWatchValue(values,allValues);constnextValueStr=stringify(newValue);// Compare stringify in case it's nest objectif(valueStrRef.current!==nextValueStr){valueStrRef.current=nextValueStr;setValue(newValue);}});// TODO: We can improve this perf in futureconstinitialValue=getWatchValue(getFieldsValue(),getFieldsValue(true));// React 18 has the bug that will queue update twice even the value is not changed// ref: https://github.com/facebook/react/issues/27213if(value!==initialValue){setValue(initialValue);}returncancelRegister;},// We do not need re-register since namePath content is the same// eslint-disable-next-line react-hooks/exhaustive-deps[isValidForm],);
The text was updated successfully, but these errors were encountered:
为什么不支持watch动态的路径呢?事实上我传一个动态的namePath,它似乎也能正常工作,只是代码里写了让它warnning。但如果我传了一个动态的selector,它不起效,selector会保持不变,我想是否因为这里effect没有依赖dependencies(when type is func)。所以为什么不加上这个依赖呢?然后不用ref来接受namePath,将namePath也放入依赖中,似乎这样就支持动态路径,而不必报错了。
The text was updated successfully, but these errors were encountered: