Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosMicrosoft Mechanics: A Copilot Agent Writes the Status Report(23.09.2026 um 03:30 Uhr)
Sichere ProgrammierungOpenTelemetry in the GitHub Copilot app(23.09.2026 um 04:14 Uhr)
Sichere ProgrammierungMy Introduction:(23.09.2026 um 03:53 Uhr)
Sichere ProgrammierungAgentWallex: Content Day (Articles going live)(23.09.2026 um 04:00 Uhr)
Sichere ProgrammierungYour Low-Code Platform Is Fast Until a Customer Builds One Real Table(23.09.2026 um 04:11 Uhr)
YouTube Security VideosMicrosoft Mechanics: A Copilot Agent Writes the Status Report(23.09.2026 um 03:30 Uhr)
Sichere ProgrammierungOpenTelemetry in the GitHub Copilot app(23.09.2026 um 04:14 Uhr)
Sichere ProgrammierungMy Introduction:(23.09.2026 um 03:53 Uhr)
Sichere ProgrammierungAgentWallex: Content Day (Articles going live)(23.09.2026 um 04:00 Uhr)
Sichere ProgrammierungYour Low-Code Platform Is Fast Until a Customer Builds One Real Table(23.09.2026 um 04:11 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

My React Journey: Day 23

Props and State PROPS Props, short for properties, are read-only and immutable data passed from parent to child components. They are mainly used to transfer data between components and ensure reusability. Key Features of…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




Props and State



PROPS

Props, short for properties, are read-only and immutable data passed from parent to child components. They are mainly used to transfer data between components and ensure reusability.



Key Features of Props




  1. Read-Only: Cannot be modified by the child component.

  2. Used in Functional and Class Components.

  3. PropTypes: Ensures props are of the correct data type during development.



age: PropTypes.number; // Throws a warning if a non-number is passed.





4.DefaultProps: Provides default values for props when none are passed.




name: "Guest"; // Default value for the name prop.






Code Example

Student.jsx




import PropTypes from 'prop-types';

export default function Student(props) {
return (
<div>
<p>Name: {props.name}</p>
<p>Age: {props.age}</p>
<p>Student: {props.isStudent ? 'Yes' : 'No'}</p>
</div>
);
}

// PropTypes
Student.propTypes = {
name: PropTypes.string,
age: PropTypes.number,
isStudent: PropTypes.bool,
};

// DefaultProps
Student.defaultProps = {
name: 'Guest',
age: 0,
isStudent: false,
};






STATE

State is an object within a component that holds dynamic values which can change over time. States are mutable and are generally used for user interactions and events.



Key Features of State




  1. Can only be used in Class Components (in older React).

  2. Mutable: Updated using this.setState().

  3. Tracks dynamic data such as user inputs or real-time responses.



App.jsx Implementation

Props are passed from the App component to the Student component.



App.jsx




import React from 'react';
import Student from './Student';

export default function App() {
return (
<>
<Student name="Damilare" age={30} isStudent={true} />
<Student name="Feyisayo" age={31} isStudent={true} />
<Student name="Inioluwa" age={4} isStudent={true} />
<Student name="Iteoluwa" age={1} isStudent={false} />
<Student /> {/* Uses defaultProps */}
<Student name="Bright" /> {/* Partial DefaultProps */}
</>
);
}






Rendering in DOM

index.js




import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';

createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>
);






Takeaways




  • Props: Immutable, passed from parent to child, and used for reusability.

  • State: Mutable, manages dynamic behavior and is updated with this.setState().

  • In modern React, hooks like useState make functional components equally capable of managing states, eliminating the need for class components.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten My React Journey: Day 23

Thematisch verwandte Begriffe: React, Journey · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-17636 | IBM Financial Transaction Manager (FTM) for RedHat OpenShift could allow…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick