Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function useSchemaForm>(key: string, schema: JSONSchema6, initialValue?: T, onFormDataChanged?: (data: T, delta: any) => void) {
const [ oldFormData, setOldFormData ] = useSetState({ ...initialValue } as any);
const [ formData, setFormData ] = useSetState(initialValue);
if (!key) {
throw new Error("key不能为空");
}
if (!schema) {
throw new Error("schema不能为空");
}
// 解析json-schema
const resolve: ResolveLib = new ResolveLib(schema as any);
// 计算当前新老数据的差异
const delta = jsonDiffPatch.diff(oldFormData, formData);
// 使用effect来处理数据的更改监听
useEffect(
export function useSchemaForm>(key: string, schema: JSONSchema6, initialValue?: T, onFormDataChanged?: (data: T, delta: any) => void) {
const [ oldFormData, setOldFormData ] = useSetState({ ...initialValue } as any);
const [ formData, setFormData ] = useSetState(initialValue);
if (!key) {
throw new Error("key不能为空");
}
if (!schema) {
throw new Error("schema不能为空");
}
// 解析json-schema
const resolve: ResolveLib = new ResolveLib(schema as any);
// 计算当前新老数据的差异
const delta = jsonDiffPatch.diff(oldFormData, formData);
// 使用effect来处理数据的更改监听
function usePreferencesStore() {
const [preferences, setPreferences] = useSetState(
initialPreferences
)
useEffect(() => {
savePreferences(preferences)
}, [preferences])
const mergedPreferences = useMemo(() => {
return {
...basePreferences,
...preferences
}
}, [preferences])
const [closed, setClosed] = useState(true)
const toggleClosed = useCallback(() => {
if (closed) {
function useGeneralStatusStore() {
const [generalStatus, setGeneralStatus] = useSetState>(
initialGeneralStatus
)
const mergedGeneralStatus = useMemo(() => {
return {
...baseGeneralStatus,
...generalStatus
}
}, [generalStatus])
const { sideNavOpenedItemList } = mergedGeneralStatus
const sideNavOpenedItemSet = useMemo(() => {
return new Set(sideNavOpenedItemList)
}, [sideNavOpenedItemList])
const toggleSideNavOpenedItem = useCallback(