Extract URL loader component

This commit is contained in:
He4eT 2021-02-24 23:04:41 +05:00
commit eb8025791b
3 changed files with 37 additions and 21 deletions

View file

@ -0,0 +1,32 @@
import { h } from 'preact'
import { useState, useEffect } from 'preact/hooks'
import { prepareVM } from '~/src/common/if'
const INITIAL_STATUS = {
stage: 'loading',
details: 'Loading...'
}
export default function ({url}) {
console.log(123, url)
const [status, setStatus] = useState(INITIAL_STATUS)
const [vm, setVM] = useState(null)
useEffect(prepareVM({
url,
setStatus,
setVM
}), [url])
useEffect(() => {
if (vm) console.log('success', vm)
}, [vm])
return (
<main>
{url}
{status.details}
</main>)
}