Skip to content

Instantly share code, notes, and snippets.

@dance2die

dance2die/ContentRepo.js

Last active Aug 12, 2018
Embed
What would you like to do?
async function* getContent(
url = `https://www.reddit.com/r/reactjs/.json?limit=2`
) {
let nextUrl = null;
while (true) {
nextUrl = nextUrl || url;
const json = await fetch(nextUrl).then(response => response.json());
nextUrl = `${url}&after=${json.data.after}`;
yield json.data.children.map(_ => _.data);
}
}
export { getContent };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.