use-constructor-hook
v0.0.6
Published
Simple contructor simulator hook for React functional components
Downloads
6
Maintainers
Readme
useConstructor
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
- 🐦 Elvis Gastelum - Author