Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Created October 19, 2023 12:16
Show Gist options
  • Save halitbatur/38fcecbc4f2a1d7cd162ad322c6484da to your computer and use it in GitHub Desktop.
Save halitbatur/38fcecbc4f2a1d7cd162ad322c6484da to your computer and use it in GitHub Desktop.
React Components and Props Discussion
  1. What is a React component, and how does it differ from a traditional JavaScript function or class?
  2. How would you describe the role of props in React? Why might they be crucial for component reusability?
  3. How do state and props differ in a React component? Can you think of scenarios where you'd use one over the other?
  4. If components are meant to be reusable, how can props help in achieving this goal? Can you think of real-world analogies or examples?
  5. In a typical React application, components are often nested within other components. How do props facilitate data flow in such hierarchies? What challenges might arise from this?
  6. React documentation emphasizes that props should be "immutable". What does this mean, and why might it be an important principle in React development?
@Yousef-AN
Copy link

Yousef-AN commented Oct 19, 2023

Q1 (recat is reusable bits of code, and it is just a plain function in JavaScript which accepts props as an argument and returns a React element)
Q2 (it allows dynamic and reusable data exchange from a parent compononet to a children compononet)
Q3 (props are read only and cannoty be modifed ,but state can be asyncronous and can be modified) Ex..(Govermental app for props becuase data cant be changed, and we can do restock an item for state.)
Q4 (it helps creating unique data for every user, Facebook User-Page)
Q5 (there could be issues with deeply nested componets )
Q6 (. Respect the Immutable Nature: Treat props, state, and context as read-only entities and also avoid modifying preexisting variables or objects)

Yousef Abunameh
Dana Omar
Mohammad issa
Ramah Madi

@Hassan-AbuGareeb
Copy link

1-React component accepts props as components and return JSX code (React element), React functional component does not
require a render function.

2-Props are used to pass data from a parent component to a child component, meanwhile state is used to manage dynamic
and changing data of a component or child component Props are immutable and cannot be changed within a component, while state is mutable and can be updated using the setState function, an example of using props would be to pass stuff that can be computed or won't be changed like a page's name or some facts, on the other hand the state would be something dynamic and changing like a score or count.

3-Props in React are a means of passing data from parent components to child components. They are crucial for component reusability because they enable customization, encourage component composition, and facilitate the dynamic updating of user interfaces. Props help maintain a clear separation of concerns, making code more maintainable and promoting efficient communication between components.

4- Card Component:
Let's say you have a Card component for displaying various types of content, such as user profiles, product details, and news articles. You can pass different data and configurations via props to render different types of cards, making the component highly reusable.

5- props facilitates data flow by passing the data in a unidirectional fashion where changes in the parent component can affect the child component, but not the other way around, plus that the child components can access the props to render the content and make decisions this helps with creating smaller reusable components, and finally when props are updated in the parent component React re-renders the child components which leads to consistency in data, challenges that may arise from this is to keep the props intact and not change them through the data transitions between components.

6- means that once you pass data to a component via props, that data should not be changed within the component. This is important because it ensures predictable and controllable behavior within the component

@MohamadSheikhAlshabab
Copy link

Team :
Mohamad
Rama alzeer
Diala abedalqader
Yara Jaber

1- A React component is a self-contained module that represents a part of a user interface (UI). It can manage its state and props (properties) and render HTML to the DOM.

Differences
Rendering: React components are meant for rendering UI, while traditional JavaScript functions or classes might be used for various other tasks.
State Management: React components can have state (with the use of React’s state management system), whereas traditional JavaScript functions can’t hold the state.
Lifecycle Methods: Class components in React have lifecycle methods that allow you to run code at particular times in the component's lifecycle, something that is not native to regular JavaScript classes.

2- Props (properties) in React are used to pass data from parent components to child components. They are crucial for component reusability because they allow the same component to be used with different data, enabling the component to render differently according to the passed props.

3- State is internal and controlled by the component itself, while props are external and controlled by whatever renders the component,
scenario : use state when we want to update element like update the counter value
use props to pass data and it's not changeable.

4-

5- Props facilitate the "downward data flow" in React applications, meaning parent components pass data to child components through props. This can help in maintaining consistency and synchronization across the application.

6 -

@Sanad-Alshobaki
Copy link

room num 15
Sanad, Ahmad, Mo’mena

Q1:
React components:  independent and reusable bits of code, it’s return HTML not like the other traditional functions.

Q2:
pass data from the parent component to the child’s components, yes it should be used to make the component customizable and easy to maintain.

Q3:
Props are used to pass data between components, while the state is used to manage the state of a component.
Props should be used to make the component customizable, while the state should be used to manage the component’s internal state.
if we change the background colour automatically when the user doesn’t click the button (state)

Q4:
if we want to build a house using React components, First, we would need to define some components that represent different parts of the house, such as walls, windows, doors, and roofs.
These components are all function components that take some props that define their dimensions and appearance.
and in this case, we can reuse the components to build other houses using the same prop.

Q5:
state is passed from the parent component to the children components via props, allowing the child components to access/manipulate that state.

Q6:
immutable => unchangeable
state that is managed by the component owner

@Dana8392
Copy link

1- React is a block of code that is reusable - the differ between (function or class) and react component is that the component can be maintained easily and work with each component as a team,
React is primarily responsible for Rendering UI elements in an efficient way.

2- is to pass the data from one component to another, we can use a component more than once by passing different props from parent to child and not vice versa.

3- State: to manage and store mutable data within a component, props: when we want to pass that variable,
Scenario: when I click the button it will update the value by passing the props to another component, when I click it again it will change the state of the component to another value .

4- Allowing you to customize and configure a component's behavior, appearance, and content based on the data passed from the parent component. --- Example: when playing the piano, you have a different set of keys that can produce different notes when played, the same as handling different input values with props.

5- parent to child data flow allows data to pass components to the child which ensures that data from parents is used and accessible, it helps in callback function challenges: the nesting would cause a layer of components to drill through which makes it harder to have a clean code that could be maintained,

6- it means that the values passed to a component via props should not be changed or mutated within that component. Instead, props should be treated as read-only values. its useful because the data flow would be more predictable, would make it more reusable, and optimize performance.

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