Component - Default props
This React Native component shows how default props work. If a prop is not given, the component uses a default value to display text. This helps keep the UI consistent and avoids errors.
This React Native component shows how default props work. If a prop is not given, the component uses a default value to display text. This helps keep the UI consistent and avoids errors.
App
└── Greeting
└── Text<Greeting /> without passing any props?function Greeting({ name = 'Guest' }) {
return Hello, {name}!;
}function Button(props) {
return {props.label};
}
Button.defaultProps = {
label: 'Click me'
};color &&= 'blue' sets 'blue' only if color is truthy (opposite). D's if (color) sets 'blue' only if truthy (wrong).Pass the test and this pattern moves unknown