React Key Concepts by Schwarzmüller Maximilian;
Author:Schwarzmüller, Maximilian;
Language: eng
Format: epub
Publisher: Packt Publishing, Limited
Published: 2022-12-21T00:00:00+00:00
Revisiting Component Evaluations and Updates
Before exploring React's internal workings, it makes sense to briefly revisit React's logic for executing component functions.
Component functions are executed whenever their internal state changes or their parent component function is executed again. The latter happens because, if a parent component function is called, its entire JSX code (which points at the child component function) is re-evaluated. Any component functions referenced in that JSX code are therefore also invoked again.
Consider a component structure like this:
function NestedChild() {
console.log('<NestedChild /> is called.');
return <p id="nested-child">A component, deeply nested into the component tree.</p>;
}
function Child() {
console.log('<Child /> is called.');
return (
<div id="child">
<p>
A component, rendered inside another component, containing yet another
component.
</p>
<NestedChild />
</div>
);
}
function Parent() {
console.log('<Parent /> is called.');
const [counter, setCounter] = useState(0);
function incCounterHandler() {
setCounter((prevCounter) => prevCounter + 1);
}
return (
<div id="parent">
<p>A component, nested into App, containing another component (Child).</p>
<p>Counter: {counter}</p>
<button onClick={incCounterHandler}>Increment</button>
<Child />
</div>
);
}
In this example structure, the Parent component renders a <div> with two paragraphs, a button, and another component: the Child component. That component in turn outputs a <div> with a paragraph and yet another component: the NestedChild component (which then only outputs a paragraph).
The Parent component also manages some state (a dummy counter), which is changed whenever the button is clicked. All three components print a message via console.log(), simply to make it easy to spot when each component is called by React.
The following screenshot shows those components in actionâafter the button was clicked:
Download
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.
ActiveX | ASP.NET |
Cold Fusion | CSS |
DHTML | Java Server Pages |
JavaScript | PHP |
Python | Ruby |
XSL |
Hello! Python by Anthony Briggs(9914)
The Mikado Method by Ola Ellnestam Daniel Brolund(9777)
Dependency Injection in .NET by Mark Seemann(9337)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Svelte with Test-Driven Development by Daniel Irvine(7150)
Test-Driven Development with PHP 8 by Rainier Sarabia(6878)
Layered Design for Ruby on Rails Applications by Dementyev Vladimir;(6747)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Web Development with Django by Ben Shaw Saurabh Badhwar(6214)
React Application Architecture for Production by Alan Alickovic(5937)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5806)
Kotlin in Action by Dmitry Jemerov(5062)
Audition by Ryu Murakami(4583)
Software Architecture for Web Developers by Mihaela Roxana Ghidersa(4449)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4316)
Accelerating Server-Side Development with Fastify by Manuel Spigolon Maksim Sinik & Matteo Collina(4296)
Functional Programming in JavaScript by Mantyla Dan(4038)
