<script lang='ts'>
  function handleClick() {
    promise = getUsers();
  }

  async function getUsers() {
		const res = await fetch("/api/users/");
		const json = await res.text();

		if (res.ok) {
			return json;
		} else {
			throw new Error(json);
		}
	}
  let promise = getUsers();
</script>

<h1>TODOs</h1>
<button on:click={handleClick}>Click Me</button>
{#await promise}
	<p>Waiting</p>
{:then users}
	<p>{users}</p>
{:catch error}
	<p style="color: red">{error}</p>
{/await}
