Made with ScholarlyMake flashcards like these from your own notes
Question:What is a functional component in React?
Answer:A reusable UI piece defined as a function returning JSX
Question:What are props used for in React?
Answer:Passing data from parent to child components
Question:What is the declarative programming approach in React?
Answer:Describe UI based on state; React updates DOM efficiently
Question:What direction does data flow in React applications?
Answer:Unidirectional from parent to child via props
Question:What are the benefits of React’s component-based approach?
Answer:Modularity, reusability, easier testing, scalable collaboration
Question:What problem does the Virtual DOM help mitigate?
Answer:Expensive direct DOM manipulations and reflows
Question:What is the purpose of npm in the React setup?
Answer:Package manager to install dependencies and manage projects
Question:What is the purpose of the useState hook in React?
Answer:To add state to functional components and trigger re-renders when updated.
Question:What does the useState hook return?
Answer:An array with the current state value and a setter function.
Question:How do you name the setter function conventionally?
Answer:Prefix the state variable name with 'set' (e.g., setCount).
Question:What happens when you call a setter from useState?
Answer:React schedules a re-render with the new state value.
Question:What is a controlled component in React?
Answer:An input whose value is controlled by React state.
Question:What pattern is used to update state from an input event?
Answer:Update the state in the onChange handler and set the input value from state.
Question:What does the submitted state boolean represent in the Greeting component example?
Answer:Whether the form has been submitted.
Question:What does event.preventDefault() accomplish in a form submission?
Answer:It stops the browser’s default form submission behavior.
Question:What is the effect of calling setSubmitted(true) after form submission?
Answer:Marks the form as submitted and can trigger different UI output.
Question:Why might a component use multiple useState calls in React?
Answer:To track several independent pieces of state separately.
Question:In the Todo item component, how is the completed state stored and updated?
Answer:As isCompleted state; toggled with setIsCompleted on checkbox change.
Question:What visual change occurs when a task is completed in the Todo item example?
Answer:Text is struck through and color changes to indicate completion.
Question:What principle combines props and state in React components?
Answer:Props configure the component from the outside; state manages internal data.
Question:What is the role of the onDelete callback in Todoltem?
Answer:Notifies the parent to remove the task from the list.
Question:What does textDecoration: 'line-through' accomplish in inline styles?
Answer:Draws a line through the text to indicate completion.
Question:What is the purpose of independent state in a React component, as described in the sample code?
Answer:Allows granular control of each piece of data without affecting others
Question:In the TodoList example, what does the deleteTask function do?
Answer:Removes the specified task from the tasks array
Question:How does Todoltem determine whether to show a task as completed?
Answer:Uses the isCompleted state to apply line-through style and color changes
Question:What prop is passed from TodoList to Todoltem to enable deletion communication?
Answer:onDelete callback
Question:What happens when a user submits the form in the TodoList component?
Answer:addTask is called; a new task is added if inputValue is non-empty
Question:What React pattern is demonstrated by Todoltem managing its own completed state while TodoList manages the list of tasks?
Answer:Child manages internal state, parent passes data via props and a callback for communication
Question:In the ColorPicker example, what is the initial color state set to?
Answer:'#000000' (black)
Question:What is the role of predefinedColors in the ColorPicker component?
Answer:Provides a list of selectable color options for the user
Question:Why is the onDelete prop important in the Todoltem component?
Answer:Enables child-to-parent communication to remove a task
Question:What does the handleMouseMove function track in the EventDemo component?
Answer:Mouse x and y coordinates (clientX, clientY)
Question:What is the purpose of a synthetic event in React?
Answer:Provides a consistent wrapper around browser events
Question:In React, what happens when you click the button that triggers an event?
Answer:The event handler receives a synthetic event object
Question:What is the primary benefit of lifting state up in a React app?
Answer:Single source of truth for shared data
Question:What does a pure component guarantee about its output?
Answer:Same output for same props and state
Question:How should event handler function names typically be prefixed in React codebases?
Answer:With handle (e.g., handleClick)
Question:What naming convention is commonly used for state setter functions in React?
Answer:set plus the state variable name (e.g., setCount)
Question:When would you render custom content conditionally in React?
Answer:When state indicates it should be shown (e.g., customColors.length > 0)
Question:What feature allows a color input to update the displayed color in the Color Picker example?
Answer:onChange event handler for the color input
Question:What is the primary purpose of React's Virtual DOM?
Answer:To improve performance by minimizing actual DOM updates
Question:Which is the correct way to update state in a functional component?
Answer:setState(newValue) where setState comes from useState
Question:What is the main difference between props and state?
Answer:State can be modified by the component; props cannot
Question:How do you handle events in React?
Answer:Using camelCase event names and passing functions
Question:What does JSX stand for?
Answer:JavaScript XML
Question:Explain the difference between controlled and uncontrolled components in React forms.
Answer:Controlled components have their value managed by React state; uncontrolled rely on DOM
Question:Why must React component names start with a capital letter?
Answer:To distinguish components from HTML elements in JSX
Question:Describe the purpose of the key prop when rendering lists in React.
Answer:Helps React identify items for efficient updates
Question:What is the significance of one-way data flow in React applications?
Answer:Data flows from parent to child, reducing complexity and side effects
Question:Explain how the useState hook works and what it returns.
Answer:Returns a state value and a setter function for that state
Question:What is the primary purpose of React's Virtual DOM?
Answer:To improve performance by minimizing actual DOM updates
Question:Which is the correct way to update state in a functional component?
Answer:setState(newValue) where setState comes from useState
Question:What is the main difference between props and state?
Answer:State can be modified by the component; props cannot
Question:How do you handle events in React?
Answer:Use camelCase event names and pass functions
Question:What does JSX stand for?
Answer:JavaScript XML
Question:Explain the difference between controlled and uncontrolled components in React forms.
Answer:Controlled components have form data controlled by React state; uncontrolled components use DOM to manage form data
Question:Why must React component names start with a capital letter?
Answer:To distinguish components from HTML elements and enable React to treat them as components
Question:Describe the purpose of the key prop when rendering lists in React.
Answer:Helps React identify item identity for efficient re-rendering
Question:What is the significance of one-way data flow in React applications?
Answer:Data flows from parent to child, simplifying reasoning and debugging
Question:Explain how the useState hook works and what it returns.
Answer:Returns a state value and a function to update it
Question:What is React's Virtual DOM purpose?
Answer:Minimize real DOM updates by reconciling a lightweight in-memory tree with the real DOM
Question:What does JSX actually compile to in React?
Answer:JavaScript function calls creating React elements