use-constructor-hook
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

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

Package Sidebar

Install

npm i use-constructor-hook

Weekly Downloads

2

Version

0.0.6

License

ISC

Unpacked Size

3.03 kB

Total Files

4

Last publish

Collaborators

  • elvisgastelum