I have a component in React in need of an array of users. I'm able to fetch one single user at a time with useUwr like so:
export function Hello(id: number) {
const { data } = useSWR('/api/user/{id}', fetcher)
return <div>hello {data.name}!</div>
}
What I need now is an array of users, so basically:
var users = [];
for(var i = 0; i < 100; i++) {
const { data } = useSWR('/api/user/{i}', fetcher);
users.push(data);
}
Issue with this approach is Error: Rendered more hooks than during the previous render.
Was thinking that there must be a smarter way to fetch the data of 100 users. Thanks for any suggestion.