JSFiddle - React, Tailwind, and code Playground

by dance2die

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>

JavaScript 1.7

/* let url = `https://www.reddit.com/r/reactjs/.json?limit=10`;
 */
async function* getContent(url = `https://www.reddit.com/r/reactjs/.json?limit=10`) {
  let after = null;
	let nextUrl = null;

  while (true) {
  	nextUrl = nextUrl || url;
    console.log(`----- calling url=${nextUrl}`);

    const json = await fetch(nextUrl).then(response => response.json());
    console.log(`===== got json!`, json);

    after = json.data.after;
    nextUrl = `${nextUrl}&after=${after}`;
    console.log(`nextUrl=${nextUrl} & after=${after}`);

    yield json.data;
  }
}

(async () => {
	const repo = await getContent();
  console.log(`value1`, (await repo.next()).value)
  console.log(`value2`, (await repo.next()).value)

/*   let after = await getContent().next();
  console.log(`value1`, after.value)
  after = await getContent().next();
  console.log(`value2`, after.value)
   */
})();