The <AutoSizer>
component provides functionality to react to changes in size in the element in which they are contained, by measuring it. When the width
or the height
of that outer element changes, the children are rerendered and will receive the new the measurements as an object.
Usage
import { AutoSizer } from 'nr1'
Examples
Basic
function render() { const style = { backgroundColor: '#d8211a1a', border: 'dashed 1px #d8211a4d', };
return ( <AutoSizer> {({ width, height }) => ( <div style={{ ...style, height, width }}> width: {width}, height: {height} </div> )} </AutoSizer> );}
Props
REQUIREDfunction | Children function that will be called every time the parent resizes. It is called with an object containing |
string | Classname for custom styling. |
function | Callback invoked when the container resizes. function ( |
enum[] | Spacing property. Spacing is defined as a tuple of zero to four values, which follow the same conventions as CSS properties like <Array of |
object | Inline style for custom styling. |
Type definitions
OnResizeArguments
{height: number, Height of the container
width: number, Width of the container
}