How to use the @shopify/react-effect.useServerEffect function in @shopify/react-effect

To help you get started, we’ve selected a few @shopify/react-effect 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 Shopify / quilt / packages / react-graphql / src / hooks / query.ts View on Github external
serializedVariables,
    normalizedFetchPolicy,
    errorPolicy,
    pollInterval,
    notifyOnNetworkStatusChange,
  ]);

  const queryObservable = useMemo(() => {
    if (skip || !watchQueryOptions) {
      return;
    }

    return client.watchQuery(watchQueryOptions);
  }, [client, skip, watchQueryOptions]);

  useServerEffect(() => {
    if (queryObservable == null) {
      return;
    }

    const result = queryObservable.getCurrentResult();
    return result.loading ? queryObservable.result() : undefined;
  });

  const defaultResult = useMemo>(
    () => createDefaultResult(client, variables, queryObservable),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    [queryObservable, client, serializedVariables],
  );

  const [responseId, setResponseId] = useState(0);
github Shopify / quilt / packages / react-async / src / hooks.ts View on Github external
export function useAsyncAsset(
  id?: string,
  {scripts, styles}: {styles?: AssetTiming; scripts?: AssetTiming} = {},
) {
  const async = useContext(AsyncAssetContext);

  useServerEffect(
    () => {
      if (async && id) {
        async.markAsUsed(id, {scripts, styles});
      }
    },
    async ? async.effect : undefined,
  );
}
github Shopify / quilt / packages / react-html / src / hooks.ts View on Github external
export function useDomEffect(
  perform: (manager: HtmlManager) => () => void,
  inputs: unknown[] = [],
) {
  const manager = useContext(HtmlContext);
  const effect = () => {
    perform(manager);
  };

  useServerEffect(effect, manager.effect);
  useEffect(effect, [manager, ...inputs]);
}
github Shopify / quilt / packages / react-network / src / hooks.ts View on Github external
export function useNetworkEffect(perform: (network: NetworkManager) => void) {
  const network = useContext(NetworkContext);

  useServerEffect(() => {
    if (network != null) {
      return perform(network);
    }
  }, network ? network.effect : undefined);
}
github Shopify / quilt / packages / react-html / src / serializer.tsx View on Github external
function Serialize({data}: SerializeProps) {
    const manager = React.useContext(HtmlContext);

    useServerEffect(
      () => {
        const result = data();
        const handleResult = manager.setSerialization.bind(manager, id);

        return typeof result === 'object' && result != null && isPromise(result)
          ? result.then(handleResult)
          : handleResult(result);
      },
      manager ? manager.effect : undefined,
    );

    return null;
  }

@shopify/react-effect

A component and set of utilities for performing effects within a universal React app

MIT
Latest version published 5 months ago

Package Health Score

62 / 100
Full package analysis

Similar packages