@@ -37,6 +37,7 @@ export const EXITING = 'exiting';
37
37
*
38
38
* ```jsx
39
39
* import { Transition } from 'react-transition-group';
40
+ * import { useRef } from 'react';
40
41
*
41
42
* const duration = 300;
42
43
*
@@ -52,18 +53,21 @@ export const EXITING = 'exiting';
52
53
* exited: { opacity: 0 },
53
54
* };
54
55
*
55
- * const Fade = ({ in: inProp }) => (
56
- * <Transition in={inProp} timeout={duration}>
57
- * {state => (
58
- * <div style={{
59
- * ...defaultStyle,
60
- * ...transitionStyles[state]
61
- * }}>
62
- * I'm a fade Transition!
63
- * </div>
64
- * )}
65
- * </Transition>
66
- * );
56
+ * function Fade({ in: inProp }) {
57
+ * const nodeRef = useRef(null);
58
+ * return (
59
+ * <Transition nodeRef={nodeRef} in={inProp} timeout={duration}>
60
+ * {state => (
61
+ * <div ref={nodeRef} style={{
62
+ * ...defaultStyle,
63
+ * ...transitionStyles[state]
64
+ * }}>
65
+ * I'm a fade Transition!
66
+ * </div>
67
+ * )}
68
+ * </Transition>
69
+ * );
70
+ * }
67
71
* ```
68
72
*
69
73
* There are 4 main states a Transition can be in:
@@ -80,11 +84,15 @@ export const EXITING = 'exiting';
80
84
* [useState](https://reactjs.org/docs/hooks-reference.html#usestate) hook):
81
85
*
82
86
* ```jsx
87
+ * import { Transition } from 'react-transition-group';
88
+ * import { useState, useRef } from 'react';
89
+ *
83
90
* function App() {
84
91
* const [inProp, setInProp] = useState(false);
92
+ * const nodeRef = useRef(null);
85
93
* return (
86
94
* <div>
87
- * <Transition in={inProp} timeout={500}>
95
+ * <Transition nodeRef={nodeRef} in={inProp} timeout={500}>
88
96
* {state => (
89
97
* // ...
90
98
* )}
@@ -390,9 +398,12 @@ class Transition extends React.Component {
390
398
391
399
Transition . propTypes = {
392
400
/**
393
- * A React reference to DOM element that need to transition:
401
+ * A React reference to the DOM element that needs to transition:
394
402
* https://stackoverflow.com/a/51127130/4671932
395
403
*
404
+ * - This prop is optional, but recommended in order to avoid defaulting to
405
+ * [`ReactDOM.findDOMNode`](https://reactjs.org/docs/react-dom.html#finddomnode),
406
+ * which is deprecated in `StrictMode`
396
407
* - When `nodeRef` prop is used, `node` is not passed to callback functions
397
408
* (e.g. `onEnter`) because user already has direct access to the node.
398
409
* - When changing `key` prop of `Transition` in a `TransitionGroup` a new
@@ -422,9 +433,9 @@ Transition.propTypes = {
422
433
* specific props to a component.
423
434
*
424
435
* ```jsx
425
- * <Transition in={this.state.in} timeout={150}>
436
+ * <Transition nodeRef={nodeRef} in={this.state.in} timeout={150}>
426
437
* {state => (
427
- * <MyComponent className={`fade fade-${state}`} />
438
+ * <MyComponent ref={nodeRef} className={`fade fade-${state}`} />
428
439
* )}
429
440
* </Transition>
430
441
* ```
0 commit comments