Components with Props In React
Components in React behave like functions. They can take in arguments and returns values.
Components take in Props (like arguments) and returns some piece of the UI for the app.
Props are objects and can have any data type as a property: number, strings, objects, functions, and even other components.
When we use a component we can pass in the props using the attribute on the JSX component. For example,
< Alert message="You need to login before you do that" />
Here, Alert is our component and we are passing the Props of 'message'.
We access that message inside our component definition using Props.message. This will equal the string "You need to login before you do that".
Props.message is "You need to login before you do that".
A few notes about Props
Props – are read-only, this is because components act like ‘pure’ functions. Pure functions are functions that don’t change their inputs. Their return value is only determined by its input values.
Leave Components with Props In React to:
Read more #react posts
Best Posts From positivelyzack
We have not curated any of positivelyzack's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From positivelyzack
- Adding props or functionality to React children
- Positive Product Design
- Half Life: The Decay of Utility of Software Knowledge or why you should learn to learn
- Pure Functions
- Deploying a fullstack React app to Heroku
- Components with Props In React
- The structure of app created with the create-react-app tool.
- ES6 Javascript exports, imports and the difference between 'default export' & 'export'