React components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This is a collection of commonly-used patterns to keep React components modular.
Props are inputs for your components. The first rule of props is:
Props should be immutable and shouldn't change during the component's lifecycle.
In the following example, a prop color is passed to a component FancyBorder. The child component also receives and utilizes the children prop.
Pass props up to parent
While the above example shows props being passed down the component chain, sometimes application logic that happens downstream needs to be applied back up in a parent component.
In the following pattern, child components utilize data- attributes to signal props to an event handler that was defined in the parent's scope:
Components as props
Props of course need not be strings and numbers. In the following example, JSX components are passed as props.
Modifying prop components
Although props should be immutable (the First Rule of Props), components as props can still be modified by using React.cloneElement to add additional props to the component:
In React, JSX components are made of React Elements, the smallest building blocks of React. And a React Element is merely a javascript object: