Usage
Props
Dimensions
number | string
default:"100%"
The width of the container.Can be a number (pixels) or a percent string like “100%”.
number | string
default:"100%"
The height of the container.Can be a number (pixels) or a percent string like “100%”.
number | string
default:"0"
The minimum width of the container.Can be a number (pixels) or a CSS string value.
number | string
The minimum height of the container.Can be a number (pixels) or a CSS string value.
number
The maximum height of the container, in pixels.
Aspect ratio
number
Width / height ratio.If specified, the height is calculated by width / aspect.
Initial state
object
default:"{width: -1, height: -1}"
The initial width and height of the container.Used before the ResizeObserver detects the actual size.Format:
{ width: number, height: number }Performance
number
default:"0"
If specified as a positive number, a debounced function is used to handle resize events.Value is in milliseconds.
function
Callback providing the updated chart width and height values.Signature:
(width: number, height: number) => voidContent
ReactNode
required
The content of the container.Can contain multiple charts, and they will all share the same dimensions.
Styling
CSSProperties
CSS styles applied to the container element.Note: width, height, minWidth, minHeight, and maxHeight are excluded as they are controlled by dedicated props.
string | number
The HTML element’s class name.
Other
string | number
Unique identifier of this component.Used as an HTML attribute
id.Notes
- ResponsiveContainer uses ResizeObserver to monitor size changes. Ensure browser support or include a polyfill.
- If you nest ResponsiveContainer inside another ResponsiveContainer, the inner one will not add another layer of responsiveness.
- When static width and height are provided (not percentages), ResponsiveContainer may skip rendering the monitoring div and provide dimensions directly.