Skip to content

elvisgastelum/useConstructor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useConstructor NPM version npm GitHub stars

useConstructor is a custom hook for do something before the first component render

Installation

npm install --save use-constructor-hook

Example:

import React, { useState } from 'react'
import { useConstructor } from 'use-constructor-hook'

import { fetchDataFromApi } from './api.js'

const App = () => {
  const [dataFetched, setDataFetched] = useState(undefined)
  useConstructor(async () => {
    const response = await fetchDataFromApi()
  })

  return (
    <div>{dataFetched || 'Loading data...'}<div>
  )
}

Support

Submit an issue

Credits