RTK Query Loader lets you create loaders for your React components.
const loader = createLoader({
useQueries: () => {
const [name, setName] = useState("charizard");
const debouncedName = useDebounce(name, 200);
const pokemon = useGetPokemon(debouncedName);
return {
queries: {
pokemon,
},
payload: {
name,
setName,
},
};
},
});
const Consumer = withLoader((props, data) => {
return (
<div>
<input
value={data.payload.name}
onChange={(e) => data.payload.setName(e.target.value)}
/>
<div>AP: {data.queries.pokemon.data.ability_power}</div>
</div>
);
}, loader);
You must log in or register to comment.