How to use @shopify/react-effect - 8 common examples

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 / testing.tsx View on Github external
export async function getUsedAssets(
  element: ReactElement,
  ...args: Arguments
) {
  const asyncAssets = new AsyncAssetManager();

  await extract(element, {
    decorate: element => (
      
        {element}
      
    ),
  });

  return asyncAssets.used(...args);
}
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;
  }
github Shopify / quilt / packages / react-server / src / render / render.tsx View on Github external
function Providers({children}: {children: React.ReactElement}) {
      return (
        
          
            
              {children}
            
          
        
      );
    }

    try {
      const app = render(ctx);
      await extract(app, {
        decorate(element) {
          return (
            
              {element}
            
          );
        },
        afterEachPass({renderDuration, resolveDuration, index, finished}) {
          const pass = `Pass number ${index} ${
            finished ? ' (this was the final pass)' : ''
          }`;
          const rendering = `Rendering took ${renderDuration}ms`;
          const resolving = `Resolving promises took ${resolveDuration}ms`;

          logger.log(pass);
          logger.log(rendering);
github Shopify / quilt / packages / koa-react-sidecar / src / render / render.tsx View on Github external
return async function render(ctx: RenderContext) {
    const app = renderFunction(ctx);
    const networkManager = new NetworkManager();
    const htmlManager = new HtmlManager();

    try {
      await extract(app, {
        decorate(app) {
          return (
            
              
                {app}
              
            
          );
        },
      });
    } catch (error) {
      logger.error(error);
      throw error;
    }

    applyToContext(ctx, networkManager);

@shopify/react-effect

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

MIT
Latest version published 4 months ago

Package Health Score

62 / 100
Full package analysis

Similar packages