React State Management Survival Quiz Quiz

  1. useState in Functional Components

    Which hook would you use to add state to a functional component in React?

    1. useState
    2. useStates
    3. userState
    4. useEffect
    5. useStat
  2. Lifting State Up

    When two sibling components both need to access or update the same state, what is the recommended approach in React?

    1. Lift the state up to the nearest common ancestor
    2. Duplicate the state in each sibling
    3. Use local state in each sibling only
    4. UseState directly in both siblings
    5. Pass functions from root to each child independently
  3. Sharing State Across Deeply Nested Components

    Which React feature allows you to avoid 'prop drilling' when many nested components need access to the same state?

    1. Context API
    2. Lifecycle Methods
    3. Hooks API
    4. usePropType
    5. Updater Function
  4. Updating State Based on Previous Value

    Given the code `setCount(count + 1);`, what problem might you encounter when updating state multiple times in a row?

    1. Stale state issues can cause unexpected values
    2. It triggers an infinite render loop
    3. It mutates the state directly
    4. It re-initializes the entire component
    5. State is updated asynchronously and skipped
  5. Correct State Update Pattern

    What is the recommended way to update state based on its previous value in React?

    1. setState(prev =u003E prev + 1)
    2. setState(state + 1)
    3. setState = prev =u003E prev + 1
    4. setStat(prev =u003E prev + 1)
    5. updateState(prev + 1)
  6. PropTypes Purpose

    Why might you use PropTypes in your React components?

    1. To validate the types of props and catch errors early
    2. To manage component local state
    3. To fetch data asynchronously
    4. To enforce strict mode globally
    5. To avoid rendering child components
  7. useEffect and State

    Which of the following is a primary use case for the useEffect hook in relation to state?

    1. Running side effects when state changes
    2. Initializing prop types
    3. Rendering components conditionally
    4. Directly mutating state values
    5. Avoiding the use of props
  8. Props vs State

    How do props and state differ in React components?

    1. State is mutable and managed internally, props are immutable and passed from parents
    2. Both are read-only inside components
    3. Props are used for local data, state for external data only
    4. State can only be updated by parent components
    5. Props cannot contain numbers or strings
  9. Avoiding Unnecessary Rerenders

    Which hook can help memoize a function to prevent unnecessary rerenders when passing it as a prop?

    1. useCallback
    2. useEffact
    3. useMemorize
    4. useMomo
    5. useCallbak
  10. Best Practice for Derived State

    If a component's data can be calculated from props, what is the recommended method for handling this in React?

    1. Calculate the value directly in the render or return method
    2. Store the derived value in state and update it manually
    3. Pass it through context
    4. Use localStorage for calculation
    5. Avoid using calculated values