import React from "react"
import { createAsync } from "@corets/async"
import { useStream } from "@corets/use-stream"
const sharedQuery = createAsync(async () => "some global data")
const Example = () => {
const stream = useStream(1000, async () => `Current date is ${new Date().toISOString()}`)
const globalStream = useStream(5000, sharedQuery, ["some", "dependencies"])
const handleReload = () => stream.run()
const handleCancel = () => stream.cancel()
if (stream.isRunning() && ! stream.getResult()) {
return <h1>Loading for the first time</h1>
}
if (stream.isErrored()) {
return <h1>There was an error :(</h1>
}
return (
<div>
Result: {stream.getResult()}
{stream.isRunning() && "Refreshing ..."}
<button onClick={handleReload}>Reload</button>
<button onClick={handleCancel}>Cancel</button>
</div>
)
}