Prop Validation Without Libraries
ReactJS
Easy
5 views
Problem Description
Create a component that safely handles missing props using defaults.
Output Format
Render a React component.
Constraints
Do not crash when props are undefined.
Official Solution
import React from 'react';
export function Welcome({ name = 'friend' }) {
return <h1 style={{ margin: 0 }}>Welcome to meetcode, {name}.</h1>;
}
export default function App() {
return (
<div style={{ padding: 16 }}>
<Welcome />
<Welcome name='Aman' />
</div>
);
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!