React Summary
Key Benefits
React
- DOM Updates are automatically managed by React
- Handled declaratively in JSX (e.g.,
onClick,onChange) - Managed via
useStateandprops - Component Reuse: Components are reusable and composable
Plain JavaScript
- Manual DOM manipulation
- Event listeners explicitly added using
addEventListener - Must store data separately and update the DOM manually
- Harder to reuse individual parts without duplication
State
- Only data that affects the UI should be in state.
Props
Summary: Props generally include:
- Data the component needs to display
- Functions to handle events
- Configurations for appearance and behavior
(Q&A)
What if the project doesn’t use React? Show the contrast between React and plain JS.
- React provides automatic state-driven rendering and modularity, while plain JS requires manual DOM updates and less component reuse.
Determine the accuracy of the following content:
- a. ✅
useStateis used for updating the data. If anything in a component is changeable (dynamic), it should be in state. - b. ⚠️ It’s not always true that computed logic must be in
App.js. The logic can also be colocated with related UI in a component if it makes the component self-contained.
- a. ✅
How do we know what kind of contribution data has if there is no initial data?
- You design the data shape (e.g.,
id,text) based on the UI requirement. Start from what needs to be displayed or interacted with, then decide the data structure.
- You design the data shape (e.g.,
What is usually included in component props?
- Types include:
type,placeholder,value,onChange,onClick,className,disabled, etc. This depends on the component’s role.
- Types include:
Does input need
onChange, and button needonClick?- ✅ Yes.
inputusesonChangeto track typing;buttonusesonClickto handle clicks.
- ✅ Yes.
When and where do we define the
onSearchfunction? Is it name convention?- Define
onSearchin the component that owns the state or handles the search logic. The name is a convention for readability; it’s not mandatory.
- Define
Give an explanation with the whole picture about code.
- See previous notes on separating concerns: logic in containers, UI in presentational components. Use
propsto pass behavior and data,stateto manage change, and routing for navigation. All together, this forms a scalable component architecture.
- See previous notes on separating concerns: logic in containers, UI in presentational components. Use