How to use the @umijs/hooks.useMount function in @umijs/hooks

To help you get started, we’ve selected a few @umijs/hooks 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 pingcap / tidb-dashboard / ui / lib / utils / useClientRequest.ts View on Github external
}
    } catch (e) {
      if (mounted.current) {
        setState({
          error: e,
          isLoading: false,
        })
      }
    }

    cancelTokenSource.current = null

    afterRequest && afterRequest()
  }

  useMount(() => {
    mounted.current = true
    if (immediate) {
      sendRequest()
    }
  })

  useUnmount(() => {
    mounted.current = false
    if (cancelTokenSource.current != null) {
      cancelTokenSource.current.cancel()
      cancelTokenSource.current = null
    }
  })

  return {
    ...state,
github pingcap / tidb-dashboard / ui / lib / utils / useClientRequest.ts View on Github external
afterRequest?.()
  }

  const ret = useClientRequest(reqFactory, {
    immediate,
    beforeRequest: myBeforeRequest,
    afterRequest: myAfterRequest,
  })

  const retRef = useRef(ret)

  useEffect(() => {
    retRef.current = ret
  }, [ret])

  useMount(() => {
    mounted.current = true
  })

  useUnmount(() => {
    mounted.current = false
    cancelNextPoll()
  })

  return ret
}
github pingcap / tidb-dashboard / ui / lib / utils / useClientRequest.ts View on Github external
error: reqFactories.map((_) => null),
    }))

    const p = reqFactories.map((_, idx) => sendRequestEach(idx))
    await Promise.all(p)
    setState((s) => ({
      ...s,
      isLoading: false,
    }))

    cancelTokenSource.current = null

    afterRequest && afterRequest()
  }

  useMount(() => {
    mounted.current = true
    if (immediate) {
      sendRequest()
    }
  })

  useUnmount(() => {
    mounted.current = false
    if (cancelTokenSource.current != null) {
      cancelTokenSource.current.forEach((c) => c.cancel())
      cancelTokenSource.current = null
    }
  })

  return {
    ...state,
github pingcap / tidb-dashboard / ui / lib / apps / SearchLogs / components / SearchHeader.tsx View on Github external
export default function SearchHeader({ taskGroupID }: Props) {
  const { t } = useTranslation()
  const navigate = useNavigate()
  const [form] = Form.useForm()
  const [isSubmitting, setSubmitting] = useState(false)
  const instanceSelect = useRef(null)

  useMount(() => {
    async function fetchData() {
      if (!taskGroupID) {
        return
      }
      const res = await client
        .getInstance()
        .logsTaskgroupsIdGet(String(taskGroupID))
      const { task_group, tasks } = res.data
      const { start_time, end_time, min_level, patterns } =
        task_group?.search_request ?? {}
      const fieldsValue: IFormProps = {
        timeRange: {
          type: 'absolute',
          value: [start_time! / 1000, end_time! / 1000],
        },
        logLevel: min_level || 2,