0.0.23 • Published 11 months ago

mg-js v0.0.23

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

React hooks

useLazyScrolling

Lazy loading images

const [Intersector] = useLazyLoading({ initPage: 0, distance: "400px"}, (page) => {
    // do your api request using page parameter and update your state
    // note: set state only that way setState(pre=>[...pre,...newData])
  })
  return (
    <div>
      {/* rendering the data */}
      {data.map(item => {
        return <img src={item.imageLink} />
      })}
      {/* put the intersector at the end */}
      <Intersector />
    </div>
  )

useObjectState

Management of object state

const [object, setObject, reset] = useObjectState({name:"johndoe",isProfession:true})
    setObject("isProfession",false) 
    // updating one value
    
    setObject({name:"johnny",isProfession:false}) 
    // updating many values

    reset(null) 
    // put null in all the values

    // alternative way for forms 👇
    useObjectState(["name","email","password"])
    // adds the string values to the object and updates them with empty string

    useObjectState(["name","email","password",{isFriendly:true,gender:null}])
    // use the alternative way and and set specific values👇

React components

If

<If condition={true}>
    <Menu>
</If>

Media query

  <MediaQuery minWidth={500} maxWidth={800} >
      <Menu>
  </MediaQuery>

Utils

timeAgo

Time ago function

timeAgo(Date.now(), "En") //At this moment
timeAgo(Date.now()-(1000*60), "En") //One minute ago
timeAgo(Date.now()-(2000*60), "En") //Before two minutes
0.0.23

11 months ago

0.0.21

11 months ago

0.0.22

11 months ago

0.0.20

2 years ago

0.0.14

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago