@@ -37,6 +37,7 @@ export const EXITING = 'exiting';
3737 *
3838 * ```jsx
3939 * import { Transition } from 'react-transition-group';
40+ * import { useRef } from 'react';
4041 *
4142 * const duration = 300;
4243 *
@@ -52,18 +53,21 @@ export const EXITING = 'exiting';
5253 * exited: { opacity: 0 },
5354 * };
5455 *
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+ * }
6771 * ```
6872 *
6973 * There are 4 main states a Transition can be in:
@@ -80,11 +84,15 @@ export const EXITING = 'exiting';
8084 * [useState](https://reactjs.org/docs/hooks-reference.html#usestate) hook):
8185 *
8286 * ```jsx
87+ * import { Transition } from 'react-transition-group';
88+ * import { useState, useRef } from 'react';
89+ *
8390 * function App() {
8491 * const [inProp, setInProp] = useState(false);
92+ * const nodeRef = useRef(null);
8593 * return (
8694 * <div>
87- * <Transition in={inProp} timeout={500}>
95+ * <Transition nodeRef={nodeRef} in={inProp} timeout={500}>
8896 * {state => (
8997 * // ...
9098 * )}
@@ -390,9 +398,12 @@ class Transition extends React.Component {
390398
391399Transition . propTypes = {
392400 /**
393- * A React reference to DOM element that need to transition:
401+ * A React reference to the DOM element that needs to transition:
394402 * https://stackoverflow.com/a/51127130/4671932
395403 *
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`
396407 * - When `nodeRef` prop is used, `node` is not passed to callback functions
397408 * (e.g. `onEnter`) because user already has direct access to the node.
398409 * - When changing `key` prop of `Transition` in a `TransitionGroup` a new
@@ -422,9 +433,9 @@ Transition.propTypes = {
422433 * specific props to a component.
423434 *
424435 * ```jsx
425- * <Transition in={this.state.in} timeout={150}>
436+ * <Transition nodeRef={nodeRef} in={this.state.in} timeout={150}>
426437 * {state => (
427- * <MyComponent className={`fade fade-${state}`} />
438+ * <MyComponent ref={nodeRef} className={`fade fade-${state}`} />
428439 * )}
429440 * </Transition>
430441 * ```
0 commit comments