Pass Query Arguments to RTK Query Hooks

Share this video with your friends

Social Share Links

Send Tweet

Our pokemon detail query is hard coded to a single pokemon. We want to be able to click on any pokemon to navigate to that pokemons detail page. Making queries dynamic in RTK Query is as easy as passing the data into the hook destructuring that data in the query function.

Instructor: [0:00] We still have the problem that no matter where we click, we always get the Bulbasaur and point back. To change that, we have to pass in either the number of the Pokémon or the name of the Pokémon here in our URL. Let's make it variable. [0:17] Let's say we want to pass in a name here and now, we have to bring that name in here in some way. Let's pass it in as an argument. Now that this is set up, we can just pass it into the hook. We take this Pokémon name here and pass it as the argument named name into our hook.

[0:43] Looking back at the browser, if we cut GO Charmander now, we get that. It works.