How to use the react-use.useSetState function in react-use

To help you get started, we’ve selected a few react-use examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nick121212 / fx-schema-form / packages / fx-schema-form-react / src / hooks / form.tsx View on Github external
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(
github nick121212 / fx-schema-form / packages / fx-schema-form-react / src / hooks / form.tsx View on Github external
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来处理数据的更改监听
github BoostIO / BoostNote.next / src / lib / preferences / store.ts View on Github external
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) {
github BoostIO / BoostNote.next / src / lib / generalStatus / store.ts View on Github external
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(