SHARE
TWEET

Untitled

a guest Sep 17th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState, useEffect } from 'react'
  2. import { Flex } from 'rebass'
  3. import styled from 'styled-components'
  4.  
  5. const Star = styled(Flex)`
  6.     width: 25px,
  7.     height: 25px,
  8.     border-radius: 50%,
  9.     left: ${p => p.w}px,
  10.     position: absolute,
  11.     background-color: white,
  12. `
  13.  
  14. export default () => {
  15.   const [stars, setStars] = useState([])
  16.  
  17.   useEffect(() => {
  18.     const r = Math.floor(Math.random() * 10) + 1
  19.     const tmp = [...stars]
  20.     for (const i = 0; i < r; i++) {
  21.       tmp.push(Math.floor(Math.random() * window.innerWidth))
  22.     }
  23.     setStars(tmp)
  24.   }, [])
  25.  
  26.   return (
  27.     <Flex style={{ position: 'relative' }}>
  28.       {stars.map(w => (
  29.         <Star w={w} />
  30.       ))}
  31.     </Flex>
  32.   )
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top