Skip to content

Commit 781ef77

Browse files
committed
docs(nodeRef): add rich component example to readme
1 parent 279ace8 commit 781ef77

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,19 @@ onStop: DraggableEventHandler,
245245
// This can be used for arbitrarily nested components, so long as the ref ends up
246246
// pointing to the actual child DOM node and not a custom component.
247247
//
248+
// For rich components, you need to both forward the ref *and props* to the underlying DOM
249+
// element. Props must be forwarded so that DOM event handlers can be attached.
250+
// For example:
251+
//
252+
// const Component1 = React.forwardRef(function (props, ref) {
253+
// return <div {...props} ref={ref}>Nested component</div>;
254+
// });
255+
//
256+
// const nodeRef = React.useRef(null);
257+
// <DraggableCore onDrag={onDrag} nodeRef={nodeRef}>
258+
// <Component1 ref={nodeRef} />
259+
// </DraggableCore>
260+
//
248261
// Thanks to react-transition-group for the inspiration.
249262
//
250263
// `nodeRef` is also available on <DraggableCore>.

0 commit comments

Comments
 (0)