Logo/

React Fundamentals and Hooks

Log in

Made with ScholarlyMake flashcards like these from your own notes

React Fundamentals and Hooks

Questions and answers

62 cards
  1. Question:What is a functional component in React?

    Answer:A reusable UI piece defined as a function returning JSX

  2. Question:What are props used for in React?

    Answer:Passing data from parent to child components

  3. Question:What is the declarative programming approach in React?

    Answer:Describe UI based on state; React updates DOM efficiently

  4. Question:What direction does data flow in React applications?

    Answer:Unidirectional from parent to child via props

  5. Question:What are the benefits of React’s component-based approach?

    Answer:Modularity, reusability, easier testing, scalable collaboration

  6. Question:What problem does the Virtual DOM help mitigate?

    Answer:Expensive direct DOM manipulations and reflows

  7. Question:What is the purpose of npm in the React setup?

    Answer:Package manager to install dependencies and manage projects

  8. Question:What is the purpose of the useState hook in React?

    Answer:To add state to functional components and trigger re-renders when updated.

  9. Question:What does the useState hook return?

    Answer:An array with the current state value and a setter function.

  10. Question:How do you name the setter function conventionally?

    Answer:Prefix the state variable name with 'set' (e.g., setCount).

  11. Question:What happens when you call a setter from useState?

    Answer:React schedules a re-render with the new state value.

  12. Question:What is a controlled component in React?

    Answer:An input whose value is controlled by React state.

  13. 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.

  14. Question:What does the submitted state boolean represent in the Greeting component example?

    Answer:Whether the form has been submitted.

  15. Question:What does event.preventDefault() accomplish in a form submission?

    Answer:It stops the browser’s default form submission behavior.

  16. Question:What is the effect of calling setSubmitted(true) after form submission?

    Answer:Marks the form as submitted and can trigger different UI output.

  17. Question:Why might a component use multiple useState calls in React?

    Answer:To track several independent pieces of state separately.

  18. Question:In the Todo item component, how is the completed state stored and updated?

    Answer:As isCompleted state; toggled with setIsCompleted on checkbox change.

  19. 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.

  20. Question:What principle combines props and state in React components?

    Answer:Props configure the component from the outside; state manages internal data.

  21. Question:What is the role of the onDelete callback in Todoltem?

    Answer:Notifies the parent to remove the task from the list.

  22. Question:What does textDecoration: 'line-through' accomplish in inline styles?

    Answer:Draws a line through the text to indicate completion.

  23. 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

  24. Question:In the TodoList example, what does the deleteTask function do?

    Answer:Removes the specified task from the tasks array

  25. 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

  26. Question:What prop is passed from TodoList to Todoltem to enable deletion communication?

    Answer:onDelete callback

  27. 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

  28. 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

  29. Question:In the ColorPicker example, what is the initial color state set to?

    Answer:'#000000' (black)

  30. Question:What is the role of predefinedColors in the ColorPicker component?

    Answer:Provides a list of selectable color options for the user

  31. Question:Why is the onDelete prop important in the Todoltem component?

    Answer:Enables child-to-parent communication to remove a task

  32. Question:What does the handleMouseMove function track in the EventDemo component?

    Answer:Mouse x and y coordinates (clientX, clientY)

  33. Question:What is the purpose of a synthetic event in React?

    Answer:Provides a consistent wrapper around browser events

  34. Question:In React, what happens when you click the button that triggers an event?

    Answer:The event handler receives a synthetic event object

  35. Question:What is the primary benefit of lifting state up in a React app?

    Answer:Single source of truth for shared data

  36. Question:What does a pure component guarantee about its output?

    Answer:Same output for same props and state

  37. Question:How should event handler function names typically be prefixed in React codebases?

    Answer:With handle (e.g., handleClick)

  38. Question:What naming convention is commonly used for state setter functions in React?

    Answer:set plus the state variable name (e.g., setCount)

  39. Question:When would you render custom content conditionally in React?

    Answer:When state indicates it should be shown (e.g., customColors.length > 0)

  40. 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

  41. Question:What is the primary purpose of React's Virtual DOM?

    Answer:To improve performance by minimizing actual DOM updates

  42. Question:Which is the correct way to update state in a functional component?

    Answer:setState(newValue) where setState comes from useState

  43. Question:What is the main difference between props and state?

    Answer:State can be modified by the component; props cannot

  44. Question:How do you handle events in React?

    Answer:Using camelCase event names and passing functions

  45. Question:What does JSX stand for?

    Answer:JavaScript XML

  46. 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

  47. Question:Why must React component names start with a capital letter?

    Answer:To distinguish components from HTML elements in JSX

  48. Question:Describe the purpose of the key prop when rendering lists in React.

    Answer:Helps React identify items for efficient updates

  49. 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

  50. Question:Explain how the useState hook works and what it returns.

    Answer:Returns a state value and a setter function for that state

  51. Question:What is the primary purpose of React's Virtual DOM?

    Answer:To improve performance by minimizing actual DOM updates

  52. Question:Which is the correct way to update state in a functional component?

    Answer:setState(newValue) where setState comes from useState

  53. Question:What is the main difference between props and state?

    Answer:State can be modified by the component; props cannot

  54. Question:How do you handle events in React?

    Answer:Use camelCase event names and pass functions

  55. Question:What does JSX stand for?

    Answer:JavaScript XML

  56. 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

  57. 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

  58. Question:Describe the purpose of the key prop when rendering lists in React.

    Answer:Helps React identify item identity for efficient re-rendering

  59. Question:What is the significance of one-way data flow in React applications?

    Answer:Data flows from parent to child, simplifying reasoning and debugging

  60. Question:Explain how the useState hook works and what it returns.

    Answer:Returns a state value and a function to update it

  61. Question:What is React's Virtual DOM purpose?

    Answer:Minimize real DOM updates by reconciling a lightweight in-memory tree with the real DOM

  62. Question:What does JSX actually compile to in React?

    Answer:JavaScript function calls creating React elements