concept prop in category isomorphic web applications
appears as: Props, prop, props, prop

This is an excerpt from Manning's book Isomorphic Web Applications: Universal Development with React.
Listing 2.6. Featured component—src/components/featured.jsx
import React from 'react'; const Featured = (props) => { const buildIngredients = (ingredients) => { #1 const list = []; ingredients.forEach((ingredient, index) => { list.push( <li className="item" key={`${ingredient}-${index}`}> {ingredient} </li> ); }); return list; } const buildSteps = (steps) => { #2 const list = []; steps.forEach((step, index) => { list.push( <li className="item" key={`${step}-${index}`}> {step} </li> ); }); return list; } return ( <div className="featured ui container segment six wide column"> <div className="ui large image"> <img src={`http://localhost:3000/assets/${props.thumbnail}`} /> </div> #3 <h3>{props.title}</h3> #3 <div className="meta"> Cook Time: {props.cookTime} </div> #3 <div className="meta"> Difficulty: {props.difficulty} </div> #3 <div className="meta"> Servings: {props.servings} </div> #3 <div className="meta"> Tags: {props.labels.join(', ')} </div> #3 <h4>Ingredients</h4> <div className="ui bulleted list"> {buildIngredients(props.ingredients)} #4 </div> <h4>Steps</h4> <div className="ui ordered list"> {buildSteps(props.steps)} #5 </div> </div> ); } Featured.defaultProps = { #6 labels: [], ingredients: [], steps: [] } export default Featured; #1 Function converts an array of ingredients into an array of list items; this is called from the render function. #2 Function takes in the steps array and converts it to a list item, called from render function. #3 Featured component is a container that renders information about the featured recipe; it renders a recipe passed in via props. #4 Function converts an array of ingredients into an array of list items; this is called from the render function. #5 Function takes in the steps array and converts it to a list item, called from render function. #6 Set properties that are arrays to defaults so if there’s no data, the component can still render. !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":3,\"ch\":66},{\"line\":3,\"ch\":68}],[{\"line\":71,\"ch\":0},{\"line\":71,\"ch\":2}],[{\"line\":18,\"ch\":66},{\"line\":18,\"ch\":68}],[{\"line\":72,\"ch\":0},{\"line\":72,\"ch\":2}],[{\"line\":37,\"ch\":65},{\"line\":37,\"ch\":67}],[{\"line\":38,\"ch\":65},{\"line\":38,\"ch\":67}],[{\"line\":41,\"ch\":65},{\"line\":41,\"ch\":67}],[{\"line\":44,\"ch\":65},{\"line\":44,\"ch\":67}],[{\"line\":47,\"ch\":65},{\"line\":47,\"ch\":67}],[{\"line\":50,\"ch\":65},{\"line\":50,\"ch\":67}],[{\"line\":73,\"ch\":0},{\"line\":73,\"ch\":2}],[{\"line\":37,\"ch\":65},{\"line\":37,\"ch\":67}],[{\"line\":38,\"ch\":65},{\"line\":38,\"ch\":67}],[{\"line\":41,\"ch\":65},{\"line\":41,\"ch\":67}],[{\"line\":44,\"ch\":65},{\"line\":44,\"ch\":67}],[{\"line\":47,\"ch\":65},{\"line\":47,\"ch\":67}],[{\"line\":50,\"ch\":65},{\"line\":50,\"ch\":67}],[{\"line\":73,\"ch\":0},{\"line\":73,\"ch\":2}],[{\"line\":37,\"ch\":65},{\"line\":37,\"ch\":67}],[{\"line\":38,\"ch\":65},{\"line\":38,\"ch\":67}],[{\"line\":41,\"ch\":65},{\"line\":41,\"ch\":67}],[{\"line\":44,\"ch\":65},{\"line\":44,\"ch\":67}],[{\"line\":47,\"ch\":65},{\"line\":47,\"ch\":67}],[{\"line\":50,\"ch\":65},{\"line\":50,\"ch\":67}],[{\"line\":73,\"ch\":0},{\"line\":73,\"ch\":2}],[{\"line\":37,\"ch\":65},{\"line\":37,\"ch\":67}],[{\"line\":38,\"ch\":65},{\"line\":38,\"ch\":67}],[{\"line\":41,\"ch\":65},{\"line\":41,\"ch\":67}],[{\"line\":44,\"ch\":65},{\"line\":44,\"ch\":67}],[{\"line\":47,\"ch\":65},{\"line\":47,\"ch\":67}],[{\"line\":50,\"ch\":65},{\"line\":50,\"ch\":67}],[{\"line\":73,\"ch\":0},{\"line\":73,\"ch\":2}],[{\"line\":37,\"ch\":65},{\"line\":37,\"ch\":67}],[{\"line\":38,\"ch\":65},{\"line\":38,\"ch\":67}],[{\"line\":41,\"ch\":65},{\"line\":41,\"ch\":67}],[{\"line\":44,\"ch\":65},{\"line\":44,\"ch\":67}],[{\"line\":47,\"ch\":65},{\"line\":47,\"ch\":67}],[{\"line\":50,\"ch\":65},{\"line\":50,\"ch\":67}],[{\"line\":73,\"ch\":0},{\"line\":73,\"ch\":2}],[{\"line\":37,\"ch\":65},{\"line\":37,\"ch\":67}],[{\"line\":38,\"ch\":65},{\"line\":38,\"ch\":67}],[{\"line\":41,\"ch\":65},{\"line\":41,\"ch\":67}],[{\"line\":44,\"ch\":65},{\"line\":44,\"ch\":67}],[{\"line\":47,\"ch\":65},{\"line\":47,\"ch\":67}],[{\"line\":50,\"ch\":65},{\"line\":50,\"ch\":67}],[{\"line\":73,\"ch\":0},{\"line\":73,\"ch\":2}],[{\"line\":53,\"ch\":65},{\"line\":53,\"ch\":67}],[{\"line\":74,\"ch\":0},{\"line\":74,\"ch\":2}],[{\"line\":57,\"ch\":65},{\"line\":57,\"ch\":67}],[{\"line\":75,\"ch\":0},{\"line\":75,\"ch\":2}],[{\"line\":63,\"ch\":65},{\"line\":63,\"ch\":67}],[{\"line\":76,\"ch\":0},{\"line\":76,\"ch\":2}]]"} !@%STYLE%@!
To write a story, you add code to the components/stories folder. There’s a file for each chapter section that uses stories. Storybook provides two functions: storiesOf and add. The first function, storiesOf, adds a new story to Storybook, which shows on the left (Chapter examples and Todo app). The section function (add) adds a specific example to the story (link displays with props, list item functional). To see this in action, review the following code:
Listing 3.8. Test the listItem done prop—components/stories/chapter_3_4.js
storiesOf('Chapter 3.4 examples', module) .add('JSX basic button', () => ()) .add('link displays with props', () => ()) .add('list item functional', () => ()) .add('list item with done prop', () => ( #1 <ListItemFunctional completeCallback={actions.complete} deleteCallback={actions.delete} name="Cleanup mess" done="true"/> #2 )) .add('list container with list item', () =>()); #1 Add a story with the add() function—pass in a title for the story and a function that returns the component you want to render. #2 Add done property—component checks for truthy value here, so you can set it to true. !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":4,\"ch\":2},{\"line\":4,\"ch\":70}],[{\"line\":5,\"ch\":4},{\"line\":5,\"ch\":59}],[{\"line\":6,\"ch\":24},{\"line\":6,\"ch\":55}],[{\"line\":7,\"ch\":24},{\"line\":7,\"ch\":43}],[{\"line\":8,\"ch\":24},{\"line\":8,\"ch\":70}],[{\"line\":1,\"ch\":34},{\"line\":1,\"ch\":36}],[{\"line\":2,\"ch\":42},{\"line\":2,\"ch\":44}],[{\"line\":3,\"ch\":38},{\"line\":3,\"ch\":40}],[{\"line\":9,\"ch\":2},{\"line\":9,\"ch\":4}],[{\"line\":10,\"ch\":46},{\"line\":10,\"ch\":48}]]"} !@%STYLE%@!
React relies on props for communication between components.