How to use the @restart/hooks/useMounted function in @restart/hooks

To help you get started, we’ve selected a few @restart/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 relay-tools / react-relay-mutation / src / index.tsx View on Github external
export function useMutation(
  mutation: MutationNode,
  userConfig: MutationConfig = {},
  /** if not provided, the context environment will be used. */
  environment?: Environment,
): [Mutate, MutationState] {
  const [state, setState] = useState>({
    loading: false,
    data: null,
    error: null,
  });

  const isMounted = useMounted();

  const relayContext = useContext(ReactRelayContext);
  const resolvedEnvironment = environment || relayContext!.environment;
  const {
    configs,
    variables,
    uploadables,
    onCompleted,
    onError,
    optimisticUpdater,
    optimisticResponse,
    updater,
  } = userConfig;

  const mutate: Mutate = useCallback(
    config => {
github jquense / react-widgets / packages / react-widgets / src / util / useFocusManager.js View on Github external
export default function useFocusManager(ref, props = {}, opts = {}) {
  const isMounted = useMounted()
  const [focused, setFocus] = useState(false)

  const events = useFocusManagerBase({
    ...opts,
    onChange: focused => {
      if (isMounted()) setFocus(focused)
    },
    isDisabled: () =>
      props.disabled === true || isInDisabledFieldset(ref.current),
    didHandle(focused, event) {
      let handler = props[focused ? 'onFocus' : 'onBlur']
      if (handler) handler(event)

      if (opts.didHandle && !event.isWidgetDefaultPrevented)
        opts.didHandle(focused, event)
    },
github jquense / react-widgets / packages / react-widgets / src / util / useScrollManager.js View on Github external
export default function useScrollManager(
  ref,
  onMove,
  getScrollParent = list => list.parentNode,
) {
  let isMounted = useMounted()
  const stateBagRef = useRef({})

  function handleScroll(selected, list, nextFocused) {
    if (!isMounted()) return

    const stateBag = stateBagRef.current

    let lastVisible = stateBag.currentVisible
    let lastItem = stateBag.currentFocused
    let shown, changed

    stateBag.currentVisible = !(!list.offsetWidth || !list.offsetHeight)
    stateBag.currentFocused = nextFocused

    changed = lastItem !== nextFocused
    shown = stateBag.currentVisible && !lastVisible
github relay-tools / relay-hooks / src / useMutation.ts View on Github external
export function useMutation(
    mutation: MutationNode,
    userConfig: MutationConfig = {},
    /** if not provided, the context environment will be used. */
    environment?: Environment,
): [Mutate, MutationState] {
    const [state, setState] = useState>({
        loading: false,
        data: null,
        error: null,
    });

    const isMounted = useMounted();

    const relayContext: any = useContext(ReactRelayContext);
    const resolvedEnvironment = environment || relayContext.environment;
    const {
        configs,
        variables,
        uploadables,
        onCompleted,
        onError,
        optimisticUpdater,
        optimisticResponse,
        updater,
    } = userConfig;

    const mutate: Mutate = useCallback(
        (config) => {

@restart/hooks

A set of utility and general-purpose React hooks.

MIT
Latest version published 3 months ago

Package Health Score

84 / 100
Full package analysis

Similar packages