I've posted some questions about SWR hook here, because in my journey trying to use it has been a little bit hard since i'm having some problems with it
Now this time the error seems small.
What i'm trying to do is to git a breakpoint in my API triying to get some data, ( and i'm using axios by the way ) now the problem is that, i have to destructure {data} from the useSWR because that's the data i'm receiving from axios, and i think that is causing a problem with an argument that i have to pass to the hook in order to make everything work.
Let me show you some code
Using useSWR
const Part1 = () => {
const router = useRouter();
const [searchBar, setSearchBar] = useState<boolean>(false);
const [userId, setUserId] = useState<dataObject>({});
const [results, setResults] = useState<string>("");
// Searchbar users
useEffect(() => {
const auth: dataObject = JSON.parse(localStorage.getItem("Auth"));
setUserId(auth);
}, []);
const { data }: multipleUsers = useSWR(
() => "http://localhost:5000/api/user/allU/" + userId.user.id,
fetcher,
"",
data
);
So as you can see, the last argument i pass to the function, is the name data because if i don't it would give me error ( as a mentioned before, i've posted a question about that problem ), and is this
Block-scoped variable 'data' used before its declaration.ts(2448)
Part1.tsx(41, 11): 'data' is declared here
Goal: what is going on there and how can i fixe that problem ? what is causing this specifically and why ?
Thanks for your time !!
UPDATE
I've changed my code, and this is the error that appears
const { data }: multipleUsers = useSWR<user[]>(
() => "http://localhost:5000/api/user/allU/" + userId.user.id,
fetcher,
""
);
ERROR
Expected 4 arguments, but got 3.ts(2554)
use-swr.d.ts(4, 99): An argument for 'Data' was not provided