From a3464e3d7c0343257e3d3872a59f8410d27f1d9e Mon Sep 17 00:00:00 2001 From: Charissa Date: Tue, 3 Jun 2025 17:14:47 -0700 Subject: [PATCH] Documentation: Clarifing described behaviour for ref callbacks --- src/content/reference/react-dom/components/common.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/content/reference/react-dom/components/common.md b/src/content/reference/react-dom/components/common.md index 9d15332139d..bb214b336b2 100644 --- a/src/content/reference/react-dom/components/common.md +++ b/src/content/reference/react-dom/components/common.md @@ -259,7 +259,13 @@ Instead of a ref object (like the one returned by [`useRef`](/reference/react/us When the `
` DOM node is added to the screen, React will call your `ref` callback with the DOM `node` as the argument. When that `
` DOM node is removed, React will call your the cleanup function returned from the callback. -React will also call your `ref` callback whenever you pass a *different* `ref` callback. In the above example, `(node) => { ... }` is a different function on every render. When your component re-renders, the *previous* function will be called with `null` as the argument, and the *next* function will be called with the DOM node. +React will also call your `ref` callback whenever you pass a *different* `ref` callback. In the above example, `(node) => { ... }` is a different function on every render. When your component re-renders, React will call the cleanup function returned by the *previous* callback (if any), and then call the *next* function with the DOM node. + + + +If your ref callback doesn't return a cleanup function, React will call the previous callback with `null` as the argument for legacy compatibility. + + #### Parameters {/*ref-callback-parameters*/}