Skip to content

Feature Request: Enhance injectQuery to Accept an Options Object #197

@jon9090

Description

@jon9090

Which @ngneat/query-* package(s) are relevant/releated to the feature request?

query

Description

Description

Currently, the injectQuery function does not accept an options object directly. This feature would enhance the usability and flexibility of the function, making it more intuitive and powerful for developers.

Current Implementation

class MyComponent {
  #query = injectQuery();

  getTodos() {
    return this.#query({
      queryKey: ['todos'] as const,
      queryFn: () => {
        return this.#http.get<Todo[]>('https://jsonplaceholder.typicode.com/todos');
      },
    });
  }
}

Proposed Change

Modify the injectQuery function to accept an options object, allowing for more streamlined and readable code. The new usage would be similar to this:

import { injectQuery } from '@tanstack/angular-query-experimental';
...
class MyComponent {
  #query = injectQuery({
    queryKey: ['todos'] as const,
    queryFn: () => {
        return this.#http.get<Todo[]>('https://jsonplaceholder.typicode.com/todos');
    },
   });
  }
}

Benefits

  1. Consistency: Aligns with other common practices of passing an options object in similar libraries.
  2. Readability: Enhances code readability and maintainability.
  3. Flexibility: Allows for easier configuration and extension of queries.

Thank you for considering this enhancement!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions