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?

@fawzitheprogrammer
Copy link

fawzitheprogrammer commented Mar 4, 2024

1 - props are used to pass data from parent to child components and are read-only, while state is used to manage data within a component and can be modified. Props are used for configuration while state is for interactivity and dynamic updates. props are immutable whereas state can change.

2- You would use state instead of props in scenarios where data needs to be managed and updated by the component itself.

3 - title: "Profile Page"
dog: "Fido"
user: { name: 'Spider Man', age: 32 }

4 -
Top Level Component:
1-CourseOverview
Props: courseData, enrolledStudents, user
State: selectedTab, expandedStudent, filterOptions
Children Components: CourseHeader, CourseTabs, StudentList

  1. Maram Qais
  2. Eman Jamal
  3. Aween Ezzat
  4. Yousra Yaarob
  5. Fawzi Gharib
  6. Koshyar Abdurahman

@ahmadqaranyfarhan
Copy link

Students Name:
Ahamd Qarany Farhan
Harivan Tahit
Mustafa Mazin
Shvan Abduhakeem
Teba Kaaed
1.
Props are used to pass data from parent to child components, and they are read-only (means you cannot change it). State is used to manage internal component data that can change over time, and it is mutable.

if you want to change the data and more flexibility.

UserDetail component would have props for title, dog, and user

the page component consists of 3 component Header Component, Button Component, Input Component, Links Component, Footer Component,
Parent : page.js component Child: everything else, but the links component consists of 2 components 1. links and 2. butoons.

@0Rawan
Copy link

0Rawan commented Mar 4, 2024

Hana Abdullah, Ahmed Jalal, Aya Hasan, Mohammed Nazar and Rawan Mustafa

  1. state: is managing data changing within the component, while props: is passing data from the parent component to the child component.

  2. when we need to mutate data within the component we use state.

  3. title, dog, user.name and user.age

  • navbar => has one component which is the login button

  • main has two components:

    • sign up form => captcha is a component
    • change things
  • footer
    state is used for the following :

  • firstName: The user's first name.
    
  • lastName: The user's last name.
    
  • email: The user's email address.
    
  • checked: Whether or not the "Send me news and offers" checkbox is checked.
    

props:
try a free course and recent grads hired elements by fetching data and passing them to the components

@PayamRasho
Copy link

PayamRasho commented Mar 4, 2024

  1. Props are like arguments you pass to a function. They're read-only and passed from parent to child components, And the State is like a
    variables inside a function. It's used to manage data that can change over time within a component.
  2. When we have a variable or data that needs to be updated
  3. The props will be (title, dog, user)
  4. Component name:
      <NavBar />
      <SignupForm>
              <FormInput label="First Name" icon="user" type="text" />
              <FormInput label="Last Name" icon="user" type="text" />
              <FormInput label="Email" icon="mail" type="email" />
      </SignupForm>
      <ChangeThings />
      <Footer />

Group Members :
Payam Rasho
Zhin Abubaker
Dawood Alkawaz
Helin Tayeb

@Omar-Khoshnaw
Copy link

Omar-Khoshnaw commented Mar 4, 2024

Done By: Afeaa, Jwan, Omer, Mohammed Kanabi


1- Props are read-only data passed from parent to child components, while state represents mutable data managed internally within a component, used to trigger re-renders upon changes.

2- when the data needs to be managed and modified within a component, triggering re-renders internally.

3- title: Profile Page, dog: Fido, user: {name: Spider Man, age: 32}

4- Header, navbar, section, form, footer, Input, links, Button


Done By: Afeaa, Jwan, Omer, Mohammed Kanabi

@AbdulrahKh
Copy link

  1. Props: Immutable data passed from parent to child components, used for configuring child components and facilitating communication between them.
    State: Mutable data managed internally within a component, representing its current condition. State changes trigger component re-renders to reflect the updated state.
  2. Use state when the data needs to be mutable and controlled by the component itself.
  3. title="Profile Page"
    dog="Fido"
    user={ name: 'Spider Man', age: 32 }
  4. one component that contains the logo and the login button, the props should be user information (first and last name, and Email Address) and there's no state and no children.
    Abdulrahman Khalil, Mawj M. Basheer, Aland Rebwar, Ninos Dinkha

@eruptinglava
Copy link

Members: ELaf Gardi , Amal Mohammed, Lava Ahmed, kanyaw Yousif , Ahmed Isam.
1- Props are used to pass data from parent to child component while state are used to manage data within component

  • useState results like [ count, setCount ] the first element will not be changed but not pass to the server while the the second the will be
  • changed and passed to the server to be displayed on the website , while props will be used for passing a specific data to child components.
  • props are Immutable while states are mutable.

2- Use state when we need to manage and update data that changes within a component, such as user input or UI interactions.

3-props = {
title: "Profile Page",
dog: "Fido",
user: { name: "Spider Man", age: 32 },
};
4- a header component, a form component, article and footer

@Leorahx
Copy link

Leorahx commented Mar 4, 2024

1. Difference between props and state in React:
props:

Used to pass data from parent components to child components.
They cannot be changed within a child component.
It can be accessed throughout the child component.
They are used to customize the behavior or appearance of a component.

state:

Used to manage the internal data of the component.
It can be changed using setState.
They can only be accessed within the component in which they are defined.
They are used to track information that can change over time.

2. When would you use state instead of props?
For internal data of the component.
For dynamic data that changes over time.
For data that requires specific behavior from the component.

3. the props are as follows:
title: "Profile Page"
dog: "Fido"
user: { name: 'Spider Man', age: 32 }

  1. Top-Level Components:
    Header:
    Props:
    logo: URL of the Flatiron School logo
    navigationLinks: An array of objects representing navigation links (text, href)
    Child Components:
    Logo
    Navigation
    Hero Section:
    Props:
    title: Main title of the page (e.g., "Become a Software Engineer")
    subtitle: Optional subtitle providing more context
    imageUrl: URL of an image to display in the hero section
    callToAction: Text and link for a call to action button (e.g., "Apply Now")

didam goran, aras yousef, sarah mustafa

@Mardin-luqman2001
Copy link

Zainab Al-Najjar, Ibrahim Muhaned, Mardin Luqman
1- The key difference between state and props is that state is managed within a component, while props are passed from a parent component to a child component. State is used to manage internal component data, while props are used to pass data from a parent component to a child component

2- If data is managed by one component, but another component needs access to that data, you'd pass the data from the one component to the other component via props.
If a component manages the data itself, it should use state to manage it

3- App: Manages overall application state.

Props: None

State: App-level state (e.g., user authentication, global settings)

Children: Various pages/components

UserDetail: Renders user details.

Props: title, dog, user

State: None (assuming no local state needed)

Children: None (if not specified)

4- Specific Page Recreation:

Identify top-level components based on the page structure and functionality.

Assign appropriate props and state based on the data and behavior required for each component.

Organize child components as needed to build the desired page layout and functionality.

@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