DEV Community

Cover image for This is your sign(al) to try TanStack Query & Angular

This is your sign(al) to try TanStack Query & Angular

Robin Goetz on March 05, 2024

In version 16, Angular released signals. A reactive primitive promised by the core team that would help take the framework to the next level. A pri...
Collapse
 
arnouddv profile image
Arnoud

Great article Robin! To elaborate on why options is returned from a function, this also allows to preserve expressions. JavaScript - like most languages, is eagerly evaluated. The only practical way to preserve expressions is to wrap them in a function.

Which allows code like this:

postQuery = injectQuery(() => ({
    // ...
    enabled: this.postId() > 0
}))
Enter fullscreen mode Exit fullscreen mode

Which means the query will be automatically enabled for you whenever the postId signal value is greater than 0. No need to separately define and pass a computed signal. This works for all the query properties.

If it becomes more complex than a simple comparison or maybe a ternary I would recommend a separate computed for code readability though.

Collapse
 
goetzrobin profile image
Robin Goetz

Thanks so much! Is it cool if I add this as a paragraph in the article?

Collapse
 
arnouddv profile image
Arnoud

Yes of course!