Learn React Hooks by Daniel Bugl

Learn React Hooks by Daniel Bugl

Author:Daniel Bugl
Language: eng
Format: epub
Tags: COM070000 - COMPUTERS / User Interfaces, COM051260 - COMPUTERS / Programming Languages / JavaScript, COM060160 - COMPUTERS / Web / Web Programming
Publisher: Packt Publishing
Published: 2019-10-18T12:22:21+00:00


The useOnMount Hook

The useOnMount Hook has a similar effect to the componentDidMount life cycle. It is used as follows:

import React from 'react'

import { useOnMount } from 'react-hookedup'

export default function UseOnMount () {

useOnMount(() => console.log('mounted'))

return <div>look at the console :)</div>

}

The preceding code will output mounted to the console when the component gets mounted (when the React component is rendered for the first time). It will not be called again when the component re-renders due to, for example, a prop change.

Alternatively, we could just use a useEffect Hook with an empty array as the second argument, which will have the same effect:

import React, { useEffect } from 'react'



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.