
Security News
curl Shuts Down Bug Bounty Program After Flood of AI Slop Reports
A surge of AI-generated vulnerability reports has pushed open source maintainers to rethink bug bounties and tighten security disclosure processes.
react-resizable
Advanced tools
A simple widget that can be resized via one or more handles.
You can either use the <Resizable> element directly, or use the much simpler <ResizableBox> element.
See the example and associated code in ExampleLayout and ResizableBox for more details.
$ npm install --save react-resizable
You must include the associated styles in your application, otherwise the resize handles will not be visible and will not work properly.
// In your JS/TS entry point:
import 'react-resizable/css/styles.css';
Or import it in your CSS:
@import 'react-resizable/css/styles.css';
If you're using a bundler that doesn't support CSS imports, you can find the styles at node_modules/react-resizable/css/styles.css and include them manually.
| Version | React Version |
|---|---|
| 3.x | >= 16.3 |
| 2.x | Skipped |
| 1.x | 14 - 17 |
This package has two major exports:
<Resizable>: A raw component that does not have state. Use as a building block for larger components, by listening to its callbacks and setting its props.<ResizableBox>: A simple <div {...props} /> element that manages basic state. Convenient for simple use-cases.<Resizable>import { Resizable } from 'react-resizable';
import 'react-resizable/css/styles.css';
class Example extends React.Component {
state = {
width: 200,
height: 200,
};
onResize = (event, {node, size, handle}) => {
this.setState({width: size.width, height: size.height});
};
render() {
return (
<Resizable
height={this.state.height}
width={this.state.width}
onResize={this.onResize}
>
<div
className="box"
style={{width: this.state.width + 'px', height: this.state.height + 'px'}}
>
<span>Contents</span>
</div>
</Resizable>
);
}
}
<ResizableBox>import { ResizableBox } from 'react-resizable';
import 'react-resizable/css/styles.css';
class Example extends React.Component {
render() {
return (
<ResizableBox
width={200}
height={200}
draggableOpts={{grid: [25, 25]}}
minConstraints={[100, 100]}
maxConstraints={[300, 300]}
>
<span>Contents</span>
</ResizableBox>
);
}
}
These props apply to both <Resizable> and <ResizableBox>. Unknown props that are not in the list below will be passed to the child component.
type ResizeCallbackData = {
node: HTMLElement,
size: {width: number, height: number},
handle: ResizeHandleAxis
};
type ResizeHandleAxis = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne';
type ResizableProps = {
children: React.Element<any>,
width: number,
height: number,
// Either a ReactElement to be used as handle, or a function
// returning an element that is fed the handle's location as its first argument.
handle: ReactElement<any> | (resizeHandle: ResizeHandleAxis, ref: ReactRef<HTMLElement>) => ReactElement<any>,
// If you change this, be sure to update your css
handleSize: [number, number] = [10, 10],
lockAspectRatio: boolean = false,
axis: 'both' | 'x' | 'y' | 'none' = 'both',
minConstraints: [number, number] = [10, 10],
maxConstraints: [number, number] = [Infinity, Infinity],
onResizeStop?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
onResizeStart?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
onResize?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
draggableOpts?: ?Object,
resizeHandles?: ?Array<ResizeHandleAxis> = ['se'],
// If `transform: scale(n)` is set on the parent, this should be set to `n`.
transformScale?: number = 1
};
The following props can also be used on <ResizableBox>:
{
style?: Object // styles the returned <div />
}
If a width or height is passed to <ResizableBox>'s style prop, it will be ignored as it is required for internal function.
You can pass options directly to the underlying DraggableCore instance by using the prop draggableOpts. See the demo for more on this.
If you override the resize handle, we expect that any ref passed to your new handle will represent the underlying DOM element.
This is required, as react-resizable must be able to access the underlying DOM node to attach handlers and measure position deltas.
There are a few ways to do this:
This requires no special treatment.
<Resizable handle={<div className="foo" />} />
You must forward the ref and props to the underlying DOM element.
class MyHandleComponent extends React.Component {
render() {
const {handleAxis, innerRef, ...props} = this.props;
return <div ref={innerRef} className={`foo handle-${handleAxis}`} {...props} />
}
}
const MyHandle = React.forwardRef((props, ref) => <MyHandleComponent innerRef={ref} {...props} />);
<Resizable handle={<MyHandle />} />
const MyHandle = React.forwardRef((props, ref) => {
const {handleAxis, ...restProps} = props;
return <div ref={ref} className={`foo handle-${handleAxis}`} {...restProps} />;
});
<Resizable handle={<MyHandle />} />
You can define a function as a handle, which will simply receive an axis (see above ResizeHandleAxis type) and ref. This may be more clear to read, depending on your coding style.
const MyHandle = (props) => {
return <div ref={props.innerRef} className="foo" {...props} />;
};
<Resizable handle={(handleAxis, ref) => <MyHandle innerRef={ref} className={`foo handle-${handleAxis}`} />} />
MIT
The react-rnd package provides resizable and draggable components. It offers more flexibility by combining both resizing and dragging functionalities in one package. Compared to react-resizable, react-rnd is more feature-rich and allows for more complex interactions.
The react-grid-layout package is a grid layout system for React that allows for both resizing and dragging of grid items. It is particularly useful for creating complex, responsive grid layouts. While react-resizable focuses solely on resizing, react-grid-layout provides a more comprehensive solution for grid-based layouts.
The re-resizable package is another alternative for creating resizable components in React. It offers a similar API to react-resizable but includes additional features such as support for resizing in all directions and more customization options. It is a good alternative if you need more control over the resizing behavior.
FAQs
A component that is resizable with handles.
The npm package react-resizable receives a total of 1,781,356 weekly downloads. As such, react-resizable popularity was classified as popular.
We found that react-resizable demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A surge of AI-generated vulnerability reports has pushed open source maintainers to rethink bug bounties and tighten security disclosure processes.

Product
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.