Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save hiba-machfej/7ecdba8f9dd8f44ec9c26c187e89d067 to your computer and use it in GitHub Desktop.

Select an option

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?

@Dilan-Ahmed
Copy link

Ali Izzaldin | Dilan Ahmed | Ahmed Sabah| Vinos Sarah | Meer Atta

  1. The difference between props and state in react : The state is used for components to internally manage the data within the component locally. On the other hand the Props are passed from a parent component to a child component unlike state which is more internally used for managing and dealing with the data part of the component.

  2. We are using state instead of props when the data we are dealing with is internally exist in the component and needs to be managed or updated by the component itself . Also, we use props when we are having a static data and the rendering is not necessary. In a nut shell, we use the state while we are working with data within the component range.

3.We will be having there props which are ( tittle , dog, user ).

  1. this question is three part ,
    part 1 , we are having 4 top level, ( nav bar , sign up , contents, footer) and each of these components are having even more components within themselves.
    part 2, everything inside the footer is a prop and it is the same for nav , in the nav ba

part 3 ,

@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