Skip to content

Instantly share code, notes, and snippets.

@Daltonic
Last active October 20, 2022 18:51

Revisions

  1. Daltonic revised this gist Oct 20, 2022. No changes.
  2. Daltonic created this gist Oct 20, 2022.
    26 changes: 26 additions & 0 deletions Product.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    import { useEffect, useState } from 'react'
    import { useParams } from 'react-router-dom'
    import { loadProduct } from '../Blockchain.Service'
    import { useGlobalState } from '../store'
    import Buyers from '../components/Buyers'
    import Details from '../components/Details'

    const Product = () => {
    const { id } = useParams()
    const [product] = useGlobalState('product')
    const [buyers] = useGlobalState('buyers')
    const [loaded, setLoaded] = useState(false)

    useEffect(async () => {
    await loadProduct(id).then(() => setLoaded(true))
    }, [])

    return loaded ? (
    <>
    <Details product={product} />
    <Buyers buyers={buyers} />
    </>
    ) : null
    }

    export default Product