Giter VIP home page Giter VIP logo

Comments (12)

riteshsp2000 avatar riteshsp2000 commented on August 17, 2024 3

This is amazing

from blog-comments.

abhibhaw avatar abhibhaw commented on August 17, 2024 2

wow awesome

from blog-comments.

TkDodo avatar TkDodo commented on August 17, 2024 1

@rchubatov you are of course right on both accounts. I guess I was rushing the publishing a bit this time 😅. If you want, I’d accept a PR to fix it (https://github.com/tkdodo/blog), otherwise I’ll do it later 😊

from blog-comments.

rchubatov avatar rchubatov commented on August 17, 2024 1

@TkDodo ,
done PR

from blog-comments.

AtticusCMBM avatar AtticusCMBM commented on August 17, 2024 1

Cool!

from blog-comments.

Katli95 avatar Katli95 commented on August 17, 2024 1

Awesome work! Loving the blog, I'm just getting started with react-query and this has been great for finding some baseline best practices.

I don't know if this will help anyone but I created a small utility to help type the context:

type QueryContext<
    keys extends { [K: string]: QueryKey | ((...params: any[]) => QueryKey) },
    mode extends keyof keys
> = keys[mode] extends (...params: any[]) => QueryKey
    ? QueryFunctionContext<ReturnType<keys[mode]>>
    : keys[mode] extends QueryKey
    ? QueryFunctionContext<keys[mode]>
    : never;

// Can then be used like this:
    const fetchTodos = async ({ queryKey: [{ state, sorting }] }: QueryContext<typeof todoKeys, "list">) => {
    ...
}

from blog-comments.

rchubatov avatar rchubatov commented on August 17, 2024

Great post as always! 👍
Your articles help me a lot, thanks for it!

I may be wrong, but it seems to me that I found typos in the examples.

In all examples

... fetchTodo(...)

should be replaced (?) with:

... fetchTodos(...)

and in the Object Query Keys example:

const todoKeys = {
  // ✅ all keys are arrays with exactly one object
  all: [{ scope: 'todos' }] as const,
  lists: () => ({ ...todoKeys.all[0], entity: 'list' } as const),
  list: (state: State, sorting: Sorting) =>
    ({ ...todoKeys.lists()[0], state, sorting } as const),
}

missing extra square brackets for the lists key:

const todoKeys = {
  // ✅ all keys are arrays with exactly one object
  all: [{ scope: 'todos' }] as const,
  lists: () => ([{ ...todoKeys.all[0], entity: 'list' }] as const),
  list: (state: State, sorting: Sorting) =>
    ({ ...todoKeys.lists()[0], state, sorting } as const),
}

from blog-comments.

rchubatov avatar rchubatov commented on August 17, 2024

And if I understand correctly the list also must be described as an array with only one object element.

const todoKeys = {
 ...
 ...
  list: (state: State, sorting: Sorting) =>
    ([{ ...todoKeys.lists(), state, sorting }] as const),
}

from blog-comments.

joshwilsonvu avatar joshwilsonvu commented on August 17, 2024

I thought query key arrays must begin with strings, is that rule obsolete?

from blog-comments.

TkDodo avatar TkDodo commented on August 17, 2024

@joshwilsonvu the query key must be a string or an array. There is no restriction of what can go in the array. The type is defined here: https://github.com/tannerlinsley/react-query/blob/4d762a4ffe16ea126c432460699f04bf73463f23/src/core/types.ts#L6

from blog-comments.

Faithfinder avatar Faithfinder commented on August 17, 2024

Feels like entity and scope should be reversed? "Todo" is an "Entity" and "List" is a scope?

from blog-comments.

TkDodo avatar TkDodo commented on August 17, 2024

@Faithfinder yes, possibly. It's just an example 😅

from blog-comments.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.