Web TippsUse custom web fonts in Google Sheets charts(08.09.2026 um 17:05 Uhr)
Web TippsIntroducing the new 1Password App for Google Chat(08.09.2026 um 18:02 Uhr)
Web TippsUse custom web fonts in Google Sheets charts(08.09.2026 um 17:05 Uhr)
Web TippsIntroducing the new 1Password App for Google Chat(08.09.2026 um 18:02 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 2 Min Lesezeit
0

Passing pros child to parent component in react typescript

↗ Quelle (dev.to)
🗣️ Stimme:

Using simple hacks you can pass data from child to parent.though it is very simple but it have a lot of use case. It mostly use for creating core component. Let's say you want to create select component where you want to pass Custom items during that time it is very helpful. There is lot of case you need it.



I have use simple hacked to pass data child to parent you may check my implementaitons below:




CODE
import React from "react";

// Define the type for the options
type Option = {
label: string;
value: string;
};

// Props for the ChildClass component
interface ChildClassProps {
// A function prop that takes an `Option` and returns a React node
customItems: (option: Option) => React.ReactNode;
}

const ParentClass: React.FC = () => {
return (
<ChildClass
customItems={(props: Option) => (
<div>
<div>{props.value}</div>
</div>
)}
/>
);
};

const ChildClass: React.FC<ChildClassProps> = ({ customItems }) => {
// Options array with objects that match the `Option` type
const options: Option[] = [
{ label: "green", value: "green" },
{ label: "blue", value: "blue" },
{ label: "red", value: "red" },
{ label: "yellow", value: "yellow" },
];

return (
<div>
<span>Child class</span>
{/* Iterate over the options and call `customItems` to render the custom content */}
{options.map((item, index) => (
<div key={index}>
{customItems(item)}
</div>
))}
</div>
);
};

export default ParentClass;







ParentClass Component:



The ParentClass component passes a customItems function as a prop to ChildClass. This function specifies how each option should be rendered.here you can pass your custom component.



ChildClass Component:



The ChildClass component iterates over the options array and calls the customItems function for each option. This allows ParentClass to define custom rendering for the options.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
Use custom web fonts in Google Sheets charts
2 Quellen
Introducing the new 1Password App for Google Chat
1 Quelle
Context-aware access controls are available for Gemini Enterprise in the Admin console
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Passing pros child to parent component in react typescript

Thematisch verwandte Begriffe: Passing, pros, child, parent · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...