A prop is an input passed from a parent React component to a child. A functional component receives props as a JavaScript argument and uses them to decide what JSX to return. For example, after loading dashboard data, App passes it to Charts with <Charts data={data} />. section 8.3
Props make chart components reusable. A scatterplot receives data, margins, and a color scale; it passes dimensions and margins to ChartContainer. For each data item, it calculates a position with D3 scales and passes the resulting coordinates, radius, and color to a Circle component. React renders the circles rather than asking D3 to add them to the DOM. section 8.6.1
Configure one circle
A parent can render <Circle cx={xScale(item.user_count)} cy={yScale(item.retention_percentage)} r={6} fill={colorScale(item.id)} />. Circle uses props.cx, props.cy, props.r, and props.fill as SVG attributes. It also accepts optional stroke and strokeWidth props, supplying defaults when they are absent. section 8.6.1
Listing 8.9 Preparing the Circle component (Circle.js)
const Circle = props => {
return (
<circle
cx={props.cx}
cy={props.cy}
r={props.r}
fill={props.fill}
stroke={props.stroke ? props.stroke : "none"}
strokeWidth={props.strokeWidth ? props.strokeWidth : 0}
/>
)
};
export default Circle;
See how the small Circle component turns received props into a reusable SVG element. section 8.6.1
Props can carry behavior as well as values. A rankings component passes an onFilterSelection callback to its filter controls. Clicking a button calls that callback with the selected ID; the parent updates its active-filter state, and the visualization changes. In a hybrid React–D3 curve, incoming data props also drive an effect that transitions the SVG path. section 8.7 section 8.7




