📖 Scenario: You are building a simple React app to show how different parts of the React ecosystem work together. This app will display a list of tasks and allow filtering them by status.
🎯 Goal: Build a React app that uses state, props, and effects to manage and display a list of tasks with a filter option.
📋 What You'll Learn
Create a list of tasks as initial data
Add a state variable to hold the current filter
Use a filter function to select tasks based on the filter state
Render the filtered tasks in a list with React components
💡 Why This Matters
🌍 Real World
This project shows how React components, state, and event handling work together to build interactive user interfaces.
💼 Career
Understanding React's ecosystem basics is essential for frontend development roles that use React for building web applications.
Progress0 / 4 steps
1
Create initial task data
Create a constant called tasks that is an array of objects. Each object should have id, title, and completed properties. Use these exact tasks: { id: 1, title: 'Learn React', completed: false }, { id: 2, title: 'Build a project', completed: true }, { id: 3, title: 'Read docs', completed: false }.
React
Hint
Use const to create the tasks array with the exact objects given.
2
Add filter state
Inside a React functional component called TaskApp, use the useState hook to create a state variable called filter with initial value 'all'. Also create the setter function called setFilter.
React
Hint
Remember to import useState from React and use it inside TaskApp.
3
Filter tasks based on state
Inside the TaskApp component, create a constant called filteredTasks that filters the tasks array. If filter is 'completed', include only tasks where completed is true. If filter is 'active', include only tasks where completed is false. Otherwise, include all tasks.
React
Hint
Use Array.filter with a function that checks the filter state and returns tasks accordingly.
4
Render filtered tasks and filter buttons
Inside the TaskApp component, return JSX that renders three buttons labeled All, Active, and Completed. Each button sets the filter state to 'all', 'active', or 'completed' respectively when clicked. Below the buttons, render an unordered list <ul> with each filteredTasks item as a list item <li> showing the task's title. Use the task's id as the key for each list item.
React
Hint
Use buttons with onClick handlers to change the filter state. Render the filtered tasks inside a <ul> with <li> elements.
Practice
(1/5)
1. Which of the following is NOT typically part of the React ecosystem?
easy
A. Express.js for backend server
B. Redux for state management
C. React Router for navigation
D. Styled Components for styling
Solution
Step 1: Identify React ecosystem tools
React ecosystem includes tools like React Router, Redux, and Styled Components for frontend tasks.
Step 2: Recognize backend tools
Express.js is a backend server framework, not part of React's frontend ecosystem.
Final Answer:
Express.js for backend server -> Option A
Quick Check:
Backend server ≠ React ecosystem [OK]
Hint: React ecosystem focuses on frontend tools, not backend servers [OK]
Common Mistakes:
Confusing backend frameworks as React tools
Thinking Redux is not part of React ecosystem
Assuming all JavaScript libraries belong to React
2. Which syntax correctly imports the useState hook from React?
easy
A. import React.useState from 'react';
B. import useState from 'react';
C. const useState = require('react');
D. import { useState } from 'react';
Solution
Step 1: Recall ES module import syntax
Named imports use curly braces: import { useState } from 'react';.
Step 2: Identify incorrect forms
Default import without braces, require syntax, and dot notation in import are invalid here.
Final Answer:
import { useState } from 'react'; -> Option D
Quick Check:
Named import uses braces [OK]
Hint: Use curly braces for named imports like useState [OK]
Common Mistakes:
Omitting curly braces for named imports
Using CommonJS require in ES modules
Trying to import with dot notation
3. What will be the output of this React component when rendered?