Empty State Component
ReactJS
Medium
6 views
Problem Description
Create an EmptyState component that shows a title, message, and an action button.
Output Format
Render a React component.
Constraints
Use props for text and button handler.
Official Solution
import React from 'react';
export function EmptyState({ title, message, actionLabel, onAction }) {
return (
<div style={{ border: '1px dashed #bbb', borderRadius: 14, padding: 16, width: 420 }}>
<h2 style={{ margin: '0 0 8px 0' }}>{title}</h2>
<p style={{ margin: '0 0 12px 0', color: '#555' }}>{message}</p>
<button type='button' onClick={onAction} style={{ padding: '10px 14px', borderRadius: 12, border: 0, background: '#0b5', color: '#fff' }}>
{actionLabel}
</button>
</div>
);
}
export default function App() {
return (
<EmptyState
title='No saved questions'
message='Save a question on meetcode to see it here.'
actionLabel='Browse topics'
onAction={() => {}}
/>
);
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!