Master React in 5 Days by Eric Sarrion

Master React in 5 Days by Eric Sarrion

Author:Eric Sarrion
Language: eng
Format: epub
ISBN: 9781484298558
Publisher: Apress


function incrValue() {

setValue(value+1);

}

function incrRef() {

valueRef.current += 1;

}

return (

<>

<button onClick={incrValue}>value + 1</button>

&nbsp;=>

value = {value};

&nbsp;&nbsp;

<button onClick={incrRef}>ref + 1</button>

&nbsp;=>

ref = {valueRef.current};

&nbsp;&nbsp;

</>

)

}

export default Counter;

The value of the variable created using useRef() is obtained through the “current” property of the object returned by useRef(). The variable is initialized to the value specified in the initValue parameter, or to undefined if no value is provided in this parameter.

The file of the App component is restored to its original content, which displays the two Counter components separated by a horizontal line.

App component displaying the two Counter components (file src/App.js) import logo from './logo.svg';

import './App.css';

import Counter from "./Counter.js";



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.