October 2019
Intermediate to advanced
426 pages
11h 49m
English
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'export default function OnMountWithEffect ...Read now
Unlock full access