React Assignment – 1
Basic Questions
- Create a functional component called HelloWorld that renders “Hello World”.
- Render the HelloWorld component inside App.js.
- Create a functional component Greeting that accepts a name prop and displays Hello, {name}.
- Pass multiple props (title, subtitle) to a functional component and display them.
- Set default props for Greeting so if no name is passed it shows “Guest”.
- Validate props in Greeting using PropTypes.string.
- Create a Button component that accepts label and onClick as props.
- Practice reusing Button component in three different places with different labels.
- Create a Card component that renders children inside a styled box.
- Compose components: render Card and inside it render Greeting.
- Demonstrate prop drilling: Pass data from App → Parent → Child.
- Refactor prop drilling with component composition (using props.children).
- Build a UserInfo component that accepts name, age, and email as props.
- Show conditional rendering inside a functional component (e.g., show “Admin Panel” if isAdmin prop is true).
- Create a simple HelloClass component that extends React.Component.
- Render text from this.props.message inside HelloClass.
- Demonstrate componentDidMount by logging a message when a class component mounts.
- Use componentDidUpdate to log when props change in a class component.
- Demonstrate componentWillUnmount by cleaning up a setInterval.
- Create a comparison component that shows the same UI rendered once with functional and once with class components.
Intermediate Questions
- Create a reusable InputField component that accepts type and placeholder props.
- Add PropTypes validation for InputField to enforce that type must be “text” or “password”.
- Compose multiple components (Header, Footer, Content) together in App.js to form a page.
- Build a ProfileCard component that shows name, photoUrl, and bio.
- Use default props to provide fallback for bio text if not provided.
- Demonstrate prop drilling by passing user data from App → Profile → ProfileDetails
- Fix the above case by lifting state up (passing props smartly).
- Refactor a functional component to destructure props directly in its parameter list.
- Create a List component that receives an array as props and renders <li> elements.
- Showcase component reusability by using the same Card with different children (Profile, Product).
- Use PropTypes to validate an array of objects passed into a ProductList.
- Demonstrate conditional rendering for multiple states (loading, error, success).
- Create a class component with a state {count: 0} and increment button.
- Use componentDidMount to fetch dummy data from an API and log response.
- Add componentDidUpdate that prints when the count changes.
- Show proper cleanup of timers in componentWillUnmount.
- Compare a counter app built with useState Hook vs class state.
- Display lifecycle method calls (mounting, updating, unmounting) in logs using a class component.
- Convert a class component with state → functional component using useEffect.
- Demonstrate passing props to both a functional and a class component and compare.
Advanced Questions
- Build a compound component (e.g., Modal with Modal.Header, Modal.Body, Modal.Footer).
- Create a ThemeProvider component using composition, pass theme data down to child components.
- Simulate deep prop drilling by passing a prop through 5 levels of nested components, then refactor using composition.
- Write a functional Form component that validates multiple fields using PropTypes.
- Build a page layout with multiple reusable components (Sidebar, Navbar, DashboardCard) using composition.
- Build a class-based Todo App showcasing componentDidMount (fetch initial todos), componentDidUpdate (log changes), and componentWillUnmount (cleanup).
- Compare how the same Todo App looks in functional with Hooks vs class with lifecycle methods.
- Show performance difference by rendering 1000 list items with functional components vs class components (profiling).
- Refactor an existing class component to a functional one with hooks (useState, useEffect) maintaining the same logic.
- Create a demo project (e.g., counter, user profile, product list) implemented once with class components and once with functional components and document the differences.