Skip to content

@data-client/react@0.19.2

Latest

Choose a tag to compare

@github-actions github-actions released this 29 Nov 23:40
da79b18

📝 Read the full release announcement


Patch Changes

  • #4718 20d93f0 - Fix getResponse() and getResponseMeta() typing data as undefined for endpoints without a schema

    Affects Controller, Snapshot, and the snap that getOptimisticResponse() receives.

    // store settings are plain JSON, so this endpoint has no schema
    const getSettings = new RestEndpoint({
      path: '/settings',
      process(value): { taxRate: number } {
        return value;
      },
    });
    
    const addToCart = new RestEndpoint({
      path: '/cart/items',
      method: 'POST',
      body: {} as { productId: string; price: number },
      schema: CartItem,
      getOptimisticResponse(snap, body) {
        const { data: settings } = snap.getResponse(getSettings);
        return {
          ...body,
          id: `optimistic-${snap.fetchedAt}`,
          // Before: Property 'taxRate' does not exist on type 'never'.
          tax: body.price * (settings?.taxRate ?? 0),
        };
      },
    });

    New exported types EndpointData<E> and EndpointDataNullable<E> are what useSuspense(), useCache(), useDLE(), useLive() and these reads return. Use them to annotate your own helpers. Docs

  • Updated dependencies [20d93f0]:

    • @data-client/core@0.19.2