React Assignment – 7
Basic Questions
- Create a ThemeContext and provide “light” as its value. Consume it in a child component and display it.
- Create a UserContext with “John” as default username. Display it inside a deeply nested child using useContext.
- Pass a counter value from App → ComponentA → ComponentB → ComponentC.
- Replace the above prop drilling with Context API.
- Build a LanguageContext with “English” as default. Display “Hello” if English, “Namaste” if Hindi.
- Create a Counter component with a button that increases count using onClick.
- Add an input box that updates text live using onChange.
- Build a Login form with onSubmit that prevents page reload and logs values in console.
- Create a button that logs both the event object and a custom message on click.
- Build a Parent and Child component where clicking the child stops the event from bubbling to the parent.
- Display “Mounted!” in console when a component first appears using useEffect.
- Display “Updated!” in console whenever a counter changes.
- Display “Component destroyed” in console when you unmount it.
- Create two buttons: one increases number, one decreases it, both via onClick.
- Build a simple toggle component that shows/hides a paragraph with a button click.
- Create a button that logs “Hello React” each time it’s clicked.
- Create a text input that converts text to UPPERCASE while typing.
- Build a checkbox group with onChange that logs checked items.
- Display a list of names and highlight the one clicked using onClick.
- Create a counter that resets to zero on button click.
Intermediate Questions
- Create a ThemeContext and UserContext. Consume both in the same Navbar component.
- Build an auth reducer with login and logout. Connect it to AuthContext. Display “Welcome, user” when logged in.
- Create a CartContext that holds a cart array. Add/remove items from multiple components.
- Create a TodoContext with useReducer. Add and delete todos globally.
- Build a login form that updates UserContext. Show logged-in user in Navbar.
- Implement a light/dark theme toggle that updates all child components at once using Context.
- Create a CounterContext with Reducer: actions → “increment”, “decrement”, “reset”.
- Build a list that filters items in real-time from input typed in a search box.
- Create a modal that mounts/unmounts based on isVisible state and logs lifecycle in console.
- Create nested Parent → Child → GrandChild with click handlers. In Child, stop event propagation.
- Create two forms (Login and Signup) and handle their submissions separately inside one component.
- Build a navbar showing cart item count from CartContext. Add item buttons in multiple child components.
- Fetch data from a fake API inside useEffect. Display “Loading…” until data arrives.
- Update Context value dynamically (switch language between English/Hindi).
- Create a component that re-renders only when a specific prop changes (using useEffect dependencies).
- Build a counter with two buttons: increment by 1, increment by 5 (handle arguments in onClick).
- Implement parent-level event delegation for a list of dynamically created buttons.
- Create a reusable CustomButton that accepts onClick prop to perform different actions.
- Develop a subscription form that prevents reload on submit and clears input after submission.
- Create a component that logs “State updated” with old & new values on every state change.
Advanced Questions
- Create a scalable structure with AuthContext, ThemeContext, CartContext, and use them in different components (Navbar, Cart, Profile).
- Implement a global reducer using Context to manage Authentication + Theme + Notifications in one state object.
- Create a dynamic form builder where input fields are stored in Context and rendered on the UI.
- Build a list where each item logs “Mounted” when added and “Unmounted” when deleted.
- Write a custom hook useAuth that uses Context + Reducer internally and exposes login, logout, and current user.
- Create a Todo App with Context+Reducer that supports add, update, delete, clear completed.
- Implement logging middleware inside a Reducer that records each action type and state change in console.
- Create an animated modal: when mounted → logs “Opening animation”, when unmounted → logs “Closing animation”.
- Implement a deep child component that triggers an event to update state in a parent component.
- Build a Lifecycle Visualizer app: dynamically add/remove components and log lifecycle (mount, update, unmount) with timestamps.