Props

A component that statically renders the same message every time is not particularly useful. It would be useful it we could pass in a name as an argument. All functions take arguments, and so do React components because they are, after all, just functions. So we pass argument through props, which look like HTML attributes. I can find a name on here. Let’s use mine, “Michael”, and then use that in the greeting component function. Now unlike traditional argument, instead of them having an order, this is going to come in as a big, gigantic object of these properties, or “props”. I can take that argument and then use the values that I get in my component. I use these little curly braces to say this is going to be a Javascript expression, and say {props.name}. Now I’m using props to provide a name dynamically to my functional component. This name can be anything. It can be “Bob”, or “Sally”, or “Bulbasaur”. Props are, quite simply, just an object of all of these attributes that get passed in to our function.

Play video: Props
  1. Course overview
  2. Project setup
  3. ReactDOM.render and React.createElement
  4. JSX
  5. Functional components
  6. 👉Props
  7. Class Components
  8. onClick and other events
  9. Component initial state
  10. setState - object form
  11. setState - functional form
  12. Conditional rendering in JSX
  13. essential react 13
  14. Fetching pokeapi data
  15. componentDidMount
  16. setState and fetch
  17. Lists with Array.map()
  18. componentWillReceiveProps
  19. Component props
  20. Render props
  21. Separation of Concerns with components
  22. Higher-order components
  23. defaultProps
  24. Render prop actions
  25. Course summary