Skip to content

Instantly share code, notes, and snippets.

@Codennnn
Created October 20, 2021 03:25
Show Gist options
  • Save Codennnn/536f754567e78f65db466611cab4b915 to your computer and use it in GitHub Desktop.
Save Codennnn/536f754567e78f65db466611cab4b915 to your computer and use it in GitHub Desktop.
/**
* 创建表单 shouldUpdate 函数的简易工具方法
*
* @param namePath - 要响应变化的表单字段,路径格式与调用 Form.getFieldValue 方法的传参一致
*/
export function shouldFormItemUpdate<Values>(
namePath: string | (string | number)[]
): (...value: [Values, Values]) => boolean {
const shouldUpdate = (...value: [Values, Values]) => {
const [prevValue, curValue] = value;
const pV = _get(prevValue, namePath);
const cV = _get(curValue, namePath);
return pV !== cV;
};
return shouldUpdate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment