Was ist ein State in React?
Sind states einfach veränderbar?
-Ja, aber nur durch setStates
Wie werden Stats über Components hin und hergereicht?
-Durch Props
Was sind Props?
Modifizieren Componentes in React ihre eigenen Props?
-Nein, da Functions/Classes in React pur sind tun sie das nicht.
Wie werden Props durch Components gereicht?
PartenComponent
Wie weißt man ein Object an eine Component?
const MeComponent = props => {
return <div>
<h1>{props.me.name}</h1>
<p>age: {props.me.age}</p>
<p>location: {props.me.location}</p>
</div>
};
const App = () => {
const myObj = name: 'Sascha', age: 25, location: 'Hamburg' };
return (
<div>
</div>
Was ist Reusability?
Worauf muss man achten um eine Component reusable zu machen?
Wie gibt man einer Component verschiedene Styles über Props?
//Optionale Klasse wie Props
const BaiscButton = props => {
return Click me! //Styling
.red [{
background: red;
}
.blue {
background: blue;
}//Reuse of Component
Wie gibt man einer React Component einen DefaultProps?
const BaiscButton = props => {
return Click me! BaisButton.defaultProps = {
ButtonStyles: ‘defaultStyles’};
.defaultStyles {
background: teal;
}
Wie kann man einen Prop als optionalen Klassennamen für eine Component einrichten?
const BaiscButton = props => {
return Click me! //Durch Stringinterpolation kann nun auch keine Klasse als leer übergeben sein
Sind alles Objects und Functions in React?
Ja, alle Components returnedn eine Art Object
Was ist die Props Chain?
Was kann man dadurch tun, da alle Compontents Objects in React returnen?
-Functions benutzen um die Objects zu returnen und große Componente Bäume zu erstellen
Was ist Prop Drilling?
Was ist ein Bespiel für eine Props Chain über mehrere Components?
const GrandChild = props => {
return <div>
<h2>{props.personData.grandChildName}</h2>
</div>
};
const Child = props => {
return <div>
<h2>{props.personData.childName}</h2>
< GrandChild persondata={props.personData} / >
</div>
};
const Parent = props => {
return <div>
<h1>{props.personData.parentName}</h1>
< Child persondata={props.personData} / >
</div>
};
const App = () => {
const personData = parentName: 'Gilbert', childname: 'Relotius', grandChildName: 'Anna' };
return (
<div>
</div>
Was ist Array.map()?
Wie kann die Array.map, JSX und React zusammen genutzt werden?
-Man kann JSX eine Map Function geben und es wird es in ein Array aus JSX Elementen wandeln, welche durch React und dann in DOM Element verwandelt werden können
Wie holt man mit Array.map first und lastname aus einem Array aus Objects mit Menschen?
const fullName = friendData.map(friend => {
return `${friend.first_name} ${friend.last_name}`;
});Wie kann man mit JSX eine Liste an Objecten handeln und dynamisch divs für diese erstellen?
const friendList = [
{ id: 1, first_name: "Anjanette", last_name: "Comelini" },
{ id: 2, first_name: "Noe", last_name: "Griffithe" },
{ id: 3, first_name: "Crichton", last_name: "Petroulis" },
];
class App extends React.Component {
constructor () {
super ();
this. state = {
name : "Freddy",
friends : friendList
};
}
render () {
return (
< div className="App">
<h1>Hello {this.state.name}< /h1>
{this. state. friends. map(friend => {
return (
< div key= {friend. id}>
{friend.first_name} {friend.last_name}
< /div>
);
})}
div>
);
}
}
</h1>Was macht man beim Iterieren über Daten für JSX?