Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hiba-machfej/7ecdba8f9dd8f44ec9c26c187e89d067 to your computer and use it in GitHub Desktop.
Save hiba-machfej/7ecdba8f9dd8f44ec9c26c187e89d067 to your computer and use it in GitHub Desktop.
# Discussion Questions: Props vs. State

Discussion Questions: Props vs. State

  1. What is the difference between props and state in React?

  2. When would you use state instead of props?

  3. Assuming UserDetail is a component, what will its props be if it's rendered as follows:

    const user = {name: 'Spider Man', age: 32}
    
    <UserDetail title="Profile Page" dog="Fido" user={user} />
  4. Take a look at https://learning.flatironschool.com. Pretend you were going to recreate a specific page. What top level components would you have? What props would they receive and what state would they own? What components would they have as children?

@Nada-235
Copy link

Nada-235 commented Mar 4, 2024

Team [ Papula , Halwest , Shkar , Shinak, and Nada ]

  1. What is the difference between props and state in React?
  • Props: We are using props to pass data from parent to child components. and it's immutable.
  • State: The internal data of the component which can change through the set function. state can be global.
  1. When would you use state instead of props?
  • State use when we have data continuously needs to change.
  • props using when we have data that don't have to be changed.
  1. Assuming UserDetail is a component, what will its props be if it's rendered as follows:
    const UserDetail = ({title,dog,user}) => {}
    its props are title,dog and user(object)

  2. Take a look at https://learning.flatironschool.com. Pretend you were going to recreate a specific page. What top level components would you have? What props would they receive and what state would they own? What components would they have as children?

Top-level Components:
Sidebar - Notification header - Dashboard - Right Section- Footer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment