Next.js Discord

Discord Forum

How to use SWR with ky lib?

Unanswered
Somali posted this in #help-forum
Open in Discord
SomaliOP
HI, i use ky to fetch data, now i have this code to get all projects

import useSWR from 'swr';

import client from '@/api/client';

import ky from 'ky';

const fetcher = (url) => client.get(url).json();

function useProjects(query, category, limit = 2) {
const { data, error, isLoading } = useSWR(
projects?query=${query}&category=${category},
fetcher,
);
return {
data,
error,
isLoading,
};
}

export default useProjects;


but i wanna use ky searchParams to set queryparams instead use query pararams inside string

so i wanna something like screenshot, how i can do this?thank you

0 Replies