React Props and React State

What’s inside React components?

At the heart of React are key elements called “components”. These components represent a DOM node and each component has its own state and properties (props). Understanding these concepts will help you better …


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Ahmed Radwan

What’s inside React components?

At the heart of React are key elements called “components”. These components represent a DOM node and each component has its own state and properties (props). Understanding these concepts will help you better understand how to use React effectively.

How would you define the React state?

This is a way for React to remember values from inside a component. For example, the variables that are initialized at the root of a function.

When you use props over state?

Props are a way to pass data or functions to a React component. They can be used when the data is immutable (Not to change). Only The component will tell how the passed props (data) will be displayed.

When you use state over props?

You use state when you need to change the passed data and make some operations before you output it for a display. You also use state when you want to keep the values from your components within that component.

Does props and state “Immutable“?

The props are immutable, meaning they shouldn’t be changed once passed from the component. The state isn't, because they're like the variables you declared inside a function. You need to process it with more operations before the function returns its value.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Ahmed Radwan


Print Share Comment Cite Upload Translate Updates
APA

Ahmed Radwan | Sciencx (2022-09-17T17:00:37+00:00) React Props and React State. Retrieved from https://www.scien.cx/2022/09/17/react-props-and-react-state/

MLA
" » React Props and React State." Ahmed Radwan | Sciencx - Saturday September 17, 2022, https://www.scien.cx/2022/09/17/react-props-and-react-state/
HARVARD
Ahmed Radwan | Sciencx Saturday September 17, 2022 » React Props and React State., viewed ,<https://www.scien.cx/2022/09/17/react-props-and-react-state/>
VANCOUVER
Ahmed Radwan | Sciencx - » React Props and React State. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/17/react-props-and-react-state/
CHICAGO
" » React Props and React State." Ahmed Radwan | Sciencx - Accessed . https://www.scien.cx/2022/09/17/react-props-and-react-state/
IEEE
" » React Props and React State." Ahmed Radwan | Sciencx [Online]. Available: https://www.scien.cx/2022/09/17/react-props-and-react-state/. [Accessed: ]
rf:citation
» React Props and React State | Ahmed Radwan | Sciencx | https://www.scien.cx/2022/09/17/react-props-and-react-state/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.