Test driving the useEffect hook
The effect callback is defined in the useEffect
hook's first input argument:
function Title() { useEffect(() => { window.title = "" }) }
The most common way of using the create
function can be defined by using the JavaScript ES6 syntax with an inline function, (() => {}
). For readers interested in learning more about JavaScript ES6, please see the Embracing JavaScript ES6 section in Chapter 10, Building a Website with React.
One of the interesting facts about this effect function is that, thanks to JavaScript closures, it can access all of the variables defined in the functional component:
function Title({ text }) { const a = 2 useEffect(() => { console.log(a) console.log(text) }) }
The create
callback function in the preceding code references both the a
variable...