React createref focus Feb 27, 2025 · Learn how to effectively use refs with functional components in React. With recent features such as Context and Hooks, the whole ecosystem has become more complete. Yet, some concepts are usually a source of struggle for beginners and even experienced developers. useRef for function components, or for React. Sep 21, 2022 · How to test useRef () without mocking useRef ()? Sometimes you need to expose some of your React component’s methods to its parent component with useImperativeHandle () and forwardRef (). For example, here is how you make a button that focuses the input: I use React. Feb 26, 2025 · Understanding the Ref Attribute in React The ref attribute in React enables direct access to a DOM element or a component instance. Aug 15, 2023 · In React, createRef is a method used to access the DOM nodes or React elements created in the render method. Jul 23, 2024 · Learn how to use refs effectively in React development with TypeScript for a type-safe and improved development experience. current Oct 24, 2023 · React refs, or references, allow you to reference and interact with DOM nodes or React components directly. 如果你把 ref 对象作为 JSX 节点的 ref 属性传递给 React,React 将设置其 current 属性。 注意事项 createRef 总是返回一个 不同的 对象。 这相当于你自己编写了 { current: null }。 在函数组件中,你可能想要使用 useRef,因为它始终返回相同的对象。 After React creates the DOM node and puts it on the screen, React will set the current property of your ref object to that DOM node. Inside the callback you can return an array of createRef values and use the array appropriately. Refs in React access DOM elements. Use useRef in functional components to retain references across re-renders, and use createRef in class components to access DOM elements or Sep 11, 2024 · Discover how ForwardRef can optimize React apps, from understanding 'refs' to practical examples and use cases. Sep 13, 2020 · Since React-16. A ref is usually created inside a component's constructor so as to make it usable throughout the component. it should automatically focus on the next sibling element i. focus() to bring it into focus if it is. Refs should only be employed when necessary, such as for focus management or imperative DOM operations that cannot be managed through React's declarative paradigm. In this example I have 2 inputs ==&gt; 1. It returns a mutable object that you attach to the element, allowing you to access and Sep 12, 2019 · I have a table list where each row has a menu button, for which I need a ref. The useRef can be challenging to understand because it behaves differently from other hooks. Aug 22, 2022 · React: createRef and useReftReact createRef and useRef When We want access some DOM element in React, or check if element exists, We can use one of this two functions. ChrisP People also ask How do you use createRef in react? Starting from React 16. You will see what they are and when to use them. second input elemen May 22, 2024 · From String Refs to react legacyref Initially, React used string refs, which are now considered legacy due to their drawbacks, such as causing performance issues and being less intuitive. Sometimes there is a requirement to modify a component that is outside of the workflow, in such cases refs in react come to the Learn why React refs may return null or undefined when accessing DOM nodes and how to resolve this issue effectively. Short for “reference”, refs are a way to access underlying DOM elements in a React component Apr 13, 2020 · Imported { createRef } from ‘react’ — see line 1. 3 version of React has introduced a new API called React. Nov 18, 2020 · How to use React refs with TypeScript in function and class components. createRef () and attached to React elements via the ref attribute. It bypasses some of React's core rules, making it more confusing to understand. It’s equivalent to Apr 26, 2024 · Learn how to use refs in React Native to directly access components and manage focus, animations, and other interactions. current. Jul 23, 2025 · React JS, a powerful and declarative JavaScript library for building user interfaces, provides a feature known as "refs" that allows developers to interact with the underlying DOM elements directly. Key differences betwen them: useRef is not changed with every rerender, createRef is changed on first render useRef. Following example shows a component that will focus to the text input when rendered. As you saw, the Typeahead class is itself generic, but the generic type doesn't matter for what you are trying to do, so you can use any to say that it is a ref to a Typeahead component React provide a way to access to a child's DOM node from a parent component by using Refs. I want to call this methods using component instance But May 13, 2024 · To create a ref in Reactjs, you can use the createRef() method provided by the React package. It was introduced in React 16. createRef () method and useRef Hook in React to simplify creating refs and interact with the HTML DOM. Refs let you access DOM elements and component instances without triggering re-renders. I am trying to dynamically focus Input in children component on props change. Dec 16, 2021 · 割と雰囲気で使っていたのでちゃんと理解したいと思います。 Refとは 基本的なRefに関しての話と、useRefを使った話の二段構成になります。まずは基本的な話から。 公式ドキュメントを読んでみましょう。 Apr 25, 2025 · Imagine you have a React application with an input field that you want to focus on immediately when a component mounts. 3 we now have another way of using Ref and that uses CreateRef. You simply create a ref by calling React. createRef will only be initialized once, after the first render. Here instead of passing a function to Ref, we can directly assign the value that we have using createRef to our input こんにちは、Reactを使った開発で遭遇するかもしれない問題について解説します。今日は、useRef と createRef の違いとそれぞれの使用例について詳しく見ていきましょう。 useRef と createRef の基本 Reactでは、useRefとcreate Refs - Create Refs Use React. Following are some things I've tried or paths I've gone down. In this screenshot of Trello, the user clicked the Add Checklist button. handleSubmit. focus() to focus the input automatically when the component mounts. A ref is like a boat line that attaches a boat to a dock. inputRef to access refs using the string type method. Refs are created with React. focus() once the component has loaded. For examples: Assume that you want to put the cursor in the user name fields when the page render. Examples are calculating the position or size of an element in order to display a tooltip based on them or to focus on a form field using . createRef() Do in a Class Component The React. createRef() API In 16. If you now pass ref={this. See more examples below. Note that the component doesn’t re-render with every increment. Dec 18, 2019 · I'm building a simple input component, like this: const InputComponent = () =&gt; { const inputField = React. This is highly useful when you need to modify a child component outside of the typical React dataflow with props. Tagged with ref, reactnative, form, input. Oct 3, 2022 · issue: Uncaught TypeError: fieldRef. Triggering imperative animations. Mar 14, 2019 · There are plenty of ways to create refs, but the easiest is React. For example, we have four components, and dataflow is second is a child of the first, third is a child of the second, and fourth is a child of Mar 7, 2024 · In React Native, “ref” (short for reference) is an object that provides a way to reference a React element or a DOM node created by a React component. createRef(), focusAtInput = () =&gt; inputField. However, sometimes you might need access to the DOM elements managed by React—for example, to focus a node, scroll to it, or measure its size and position. You can create refs using React. We pass our ref down to <FancyButton ref={ref}> by specifying it as a JSX attribute. Caveats createRef always returns a different object. React creates a ref object using the useRef hook in functional components or React. If you are using an earlier version of React you should use callback refs. Group Name, 2. In this article, we’ll explore two main approaches for Feb 14, 2024 · React will call the ref callback with the DOM element when the component mounts, and call it with null when it unmounts. Refs are commonly assigned to an instance property when a component is constructed so they can be referenced throughout the component. It can be used to get the value of an element, set the value of an element, or invoke a method on an element. we recommend using either the callback pattern or the createRef API instead. createRef() 所產生的,它藉由 ref 參數被依附在 React element。 Nov 19, 2015 · I'm using Typescript with React. Inside the componentDidMount lifecycle method, we call this. We create a React ref by calling React. createRef() method is used to initialize a ref value inside a class component. createRef and assign it to a ref variable. createRef() API。 如果你是利用比較舊版本的 React,我們推薦使用 callback refs。 建立 Ref Ref 是藉由使用 React. Do not use state when it's not useful anymore. createRef() function and attached to an HTML element in a React component via the ref attribute. 3 The example above uses React. createRef() method, and it's attached to an element like any other attribute. In this example, createRef() is used to create a ref named inputRef. Actually i have some custom methods like sorting and formatting in my component. And now you know how to set focus on input after render in React 16. To do this, we need to make sure the child component has been decorated with the forwardRef function, and the parent needs to create refs using useRef and then pass that ref using the ref See more examples below. Use useRef in functional components to retain references across re-renders, and use createRef in class components to access DOM elements or Mar 20, 2023 · Overview React works on the concept of breaking the code into smaller components, these small components help us to focus on specific areas. Refs are useful for accessing and interacting with the underlying instances of React elements. If we were to use a class component for implementing the same above focus functionality, it would be like this: この資料は、Coral Capitalの主催するスタートアップ React LTに株式会社 kikitoriの CTO として登壇した際の内容を再編集したものです。 サンプルコード等は、以下のリポジトリで公開しています。 概要 React における Ref は、宣言 Jan 21, 2021 · Behind the scenes react will link that variable to the native dom element on which you can call the primitive focus function. createRef() Jul 12, 2025 · Learn how to use refs and forwardRef in React class and function components with detailed examples and use cases for real projects. createRef() to create the refs for each item (not the useRef hook!) By using the useMemo hook, we make sure to only recreate the refs if the items array changes. Jan 6, 2023 · In React, the ref attribute is a way to access the properties of a DOM element. Feb 2, 2021 · Try this: const ScreenOne = () => { constructor(){ super() this. Aug 17, 2019 · Here’s how to use the createRef method or the useRef hook to interact with DOM nodes directly in your React apps. createRef () Attach the Ref to a React Element using the ref attribute Assign the Ref to an instance property in the Constructor Refs are the shorthand, similar to the React keys. createRef as a function, I'm getting at least able to read the message which is Uncaught TypeError: Cannot read property 'value' of undefined. createRef() and attached to React elements via the ref attribute. createRef(); Feb 1, 2021 · React refs are a useful and powerful tool that we can use to get even more control over the elements in our application. Unlike state, ref is a plain JavaScript object with the current property that you can read and modify. Mar 23, 2019 · Using react-select v2, I want to show and focus on the Select element when the user hits a certain key. createRef()) for the input's ref-attribute. What Does React. Still, sometimes the child component is out of the typical dataflow of components. focus is not a function, can't focus element Asked 4 years, 5 months ago Modified 4 years, 5 months ago Viewed 1k times Jun 22, 2018 · Refs can be created by using the React. For example, we have four components, and dataflow is second is a child of the first, third is a child of the second, and fourth is a child of Jul 23, 2025 · In class components, ref is a special attribute used to reference DOM elements or React components. Place your focus logic in useEffect (function components) or componentDidMount (class components) so the DOM element is ready. A ref, when attached to a react element, allows direct access to a dom element, making it possible to perform operations on an HTML dom element or trigger imperative animations on a dom element. createRef() and then attached to React elements via the ref attribute. With callback refs we need to pass a function (instead of ref attribute created by React. js is often a neglected React hook for interview preparation. May 15, 2018 · An overview of the React createRef API callbackRef API, and forward Ref API as of version 16. Calling . It opened a menu, with the Title text input autofocused and its text selected. Manipulating the DOM with Refs React automatically updates the DOM to match your render output, so your components won’t often need to manipulate it. Refs are generally used for the following purposes: Managing focus, text selection, or media playback. Mar 1, 2019 · Because useMemo accepts a callback as an argument instead of a value, React. Refs provide a way to access the underlying DOM node or React component instance and can be especially useful when you need to manage focus, control animations, or store previous state values. current contains The input node Element, with that you can access all its methods like focus (), blur (), click () … You can create a Ref Object with CreateRef API inside ClassComponent or UseRef Hook inside functional components. They are used for references in React, to store a reference to particular DOM nodes or React elements, to access React DOM nodes or React elements, to interact with React DOM nodes or React elements and to change the value of a child component, without using props. The focusInput method uses this ref to focus the input element when the button is clicked. You create a ref in the constructor, attach it to the element, and then manipulate it using the ref object. e. Refs are created using React. Class Components: Utilising the createRef method of Mar 9, 2022 · React state are often overused because React ref are misunderstood. How to Use React Ref React provides two Sep 29, 2024 · Understanding Refs in ReactJS: A Practical Guide with Code In React, refs (short for references) provide a way to access DOM elements or React elements created in the render method. If you have a custom input component then the ref attribute can be used to store a reference to the DOM node and the focus () method to explicitly focus the custom input element. focus is not a function error in React-hook-form setFocus with Reactstrap Input #9126 Jan 15, 2024 · A ref in React provides a way to access the DOM nodes or React elements created in the render method. But is there any difference between the two (CreateRef API vs UseRef Hook)? Apr 28, 2022 · How to focus a text field when the page gets loaded in React using createRef ()? Asked 3 years, 2 months ago Modified 3 years, 1 month ago Viewed 793 times Aug 20, 2025 · What are Refs in React? Refs in React provide a way to access the DOM nodes or React components directly. In an Feb 28, 2023 · In ReactJS, refs are used to referring any node of the document. 請參閱 提升 State 這篇指南裡面的範例。 注意 以下的範例已經被更新為使用 React 16. In child component, we create Refs by using React. この資料は、Coral Capitalの主催するスタートアップ React LTに株式会社 kikitoriの CTO として登壇した際の内容を再編集したものです。 サンプルコード等は、以下のリポジトリで公開しています。 概要 React における Ref は、宣言 Jan 21, 2021 · Behind the scenes react will link that variable to the native dom element on which you can call the primitive focus function. inputRef. inputRef} to an <input> in your JSX, React will populate this. Once the ref is attached to an element, it can be used to get the value of the Sep 6, 2024 · Explore how to "react get reference to element" using the ref attribute, the importance of refs for managing focus, media playback, and text input. May 21, 2024 · In class components, refs are typically created using ' React. 3 所引入的 React. I have tried creating the refs like this: const {rows} = props; cons Oct 23, 2024 · The React team's focus on enhancing integration with concurrent features, server components, and improved performance and safety signals a promising future for refs in React. My code is as f React Ref: Syntax, Usage, and Examples React refs give you direct access to DOM elements or component instances without triggering re-renders. ref_input = React. Refs provide a way to interact with the underlying DOM elements, and they can be useful in various scenarios, such as managing focus, triggering animations, or integrating third-party libraries. For example: Jun 6, 2016 · Recommended for hooks-based React Ref forwarding is an opt-in feature that lets some components take a component reference they receive, and pass it further down (in other words, “forward” it) to a child. createRef for any component. Jun 17, 2019 · The React API is fairly simple, even though it has been growing bigger. 3. It's used when you need direct access to a DOM node, for things like managing focus, text selection, or media playback. To achieve the focus of any element we can call the focus () method. We don't need to create a callback function and assign it to ref props here. It’s equivalent to Mar 17, 2021 · When the ref attribute is used on an HTML element, the ref created in the constructor with React. createRef (); const fieldThree = React. Enhance your skills and streamline your development process—read the guide now! Aug 15, 2023 · In React, createRef is a method used to access the DOM nodes or React elements created in the render method. Like state, refs are retained by React between re-renders. You might stumble across callback refs or string refs in legacy codebases, but new code shouldn't use them without a good reason. Parameters createRef takes no parameters. Use cases include managing focus and integrating third-party libraries. Generally, we can pass the props to children elements to interact with children from the parent's state. focus() method on the current property will set the focus on our input element. I can do this with Ref を作成する Ref は React. Dec 5, 2023 · Using Refs for focus control This is one of the most common use cases of using React Refs. createRef ()', while functional component employ the ' useRef' hook in function component. There are two different ways to do this which is shown below. Functional and Class components. The ref attribute is created using the React. Feb 20, 2025 · Understanding React Refs and the createref method The createref method is a built-in React function used to create refs in React. handleSubmit = this. createRef() を使用して作成され、 ref 属性を用いて React 要素に紐付けられます。 Ref は通常、コンポーネントの構築時にインスタンスプロパティに割り当てられるため、コンポーネントを通して参照が可能です。 Aug 7, 2021 · When I try to update, even after invoking React. But they all have one thing in common. In order for it to work, I need to focus on a certain element. Oct 28, 2020 · The variable typeahead which you created from createRef is a RefObject with a property current that references your component. Sep 19, 2019 · Focus on the next input after edit on current text input on React Native. Unlike createRef, which creates a new ref on each render, useRef returns the same ref Code snippet 7. In React all the data flow happens through state and props. However, setting state re-renders a component Feb 20, 2025 · In this example, createRef is used to create a ref object assigned to this. Sep 27, 2018 · React < 16. I am using react mui in my project and it's menu. createRef を使う方法で実現できます。 それぞれの違いと利点を理解することで、適切な方法を選択できるようになります。 Oct 4, 2019 · The Solution: The React framework consists of two types of components. createRef() in class components or useRef() in functional components. current property is undefined, and with next rerender it is the same ref to DOM element (current property is not Reference useImperativeHandle(ref, createHandle, dependencies?) Call useImperativeHandle at the top level of your component to customize the ref handle it exposes: Aug 7, 2018 · Instead of replying, I’ve decided to write down this “short post” about how to handle React DOM refs and ref forwarding with TypeScript for anyone new to React and TypeScript as I didn’t Notice that we're using React. React provide a way to access to a child's DOM node from a parent component by using Refs. Oct 24, 2023 · React refs, or references, allow you to reference and interact with DOM nodes or React components directly. createRef() function. I'm having trouble understanding how to use refs so as to get static typing and intellisense with respect to the react nodes referenced by the refs. Feb 24, 2021 · Refs are a React feature which let you directly access DOM nodes created by a component's render() method. If you pass the ref object to React as a ref attribute to a JSX node, React will set its current property. When I set a ref to the Select React refs are for managing playback, focus, and text selection. However, in these examples I will use one for each component type. Returns createRef returns an object with a single property: current: Initially, it’s set to the null. Using Callback Refs Callback refs provide an alternative way to set a ref to a DOM element or component instance Oct 6, 2020 · I have 'textRef' created in parent component and passed to children component using createRef(). Dec 9, 2019 · I have one more question: ``` const fieldOne = React. Refs provide a way to interact with the underlying DOM elements, and they can be useful Oct 25, 2019 · 3 ways to autofocus an input in React that ALMOST always work! October 25, 2019 / Toggle theme Autofocusing is a neat thing you can do to make your app easier to use. You can later set it to something else. Dive into ReactJS ForwardRef!. Dec 13, 2024 · The useRef hook provided by React. createRef() this. React has evolved over the years and so have the methods dealing with Refs. Group Descri Jun 12, 2024 · It is equivalent to the React. This method returns an object that represents the ref. It’s equivalent to Feb 18, 2021 · You will see that our ref. In this article, we will dive deep into React See more examples below. compilerOptions: strict: true or strictNullChecks: Tagged with typescript, javascript, react. With this autofocusing, the user doesn't have to click on the text input See more examples below. You’ll learn when to use refs Sep 4, 2020 · Adding a ref to a DOM element Consider an example of focusing a text input on clicking a button: To do this, create a ref object that holds the text input DOM node and access the DOM API to focus the input, as show below: class App extends React. This ref is attached to the <input> element via the ref attribute. createRef (); ``` How can I make it one sentence? Jan 10, 2021 · Hello everyone! 👋 Lately, I have been working a bit with refs in functional components and decided Tagged with react, javascript. 3, the React API included a createRef () method that can be used for creating refs in much the same way as we did using the callback function. The modern approach in React is to use the createref function for class components or the useref hook for functional components. Component { // create a ref to hold the textInput DOM element textInput = React. tsx in the whole app. They are commonly used to perform actions like accessing the DOM directly, managing focus, or triggering animations. However, refs enable direct access to the DOM node, making tasks like auto-focusing an input element straightforward. Feb 1, 2020 · Using React. Apr 15, 2024 · All scenarios in this article are under tsconfig. Yet, interviewers focus on it as much as they do on other core React concepts. When you create the ref, you need to specify the component type with the generic. Reactにおけるフォームフィールドのフォーカス設定は、関数コンポーネントの useRef とクラスコンポーネントの React. What I need is when the user inputs a value in one input field. I use just one input called GeneralTextInput. Feb 27, 2025 · How do you manage refs in React? Do you use useRef in functional components or createRef in class components? Understanding both can help you write better code. Jun 25, 2020 · React Refs Refs can be used to access DOM nodes or React components that are rendered in the render method. useRef is a hook that provides a mutable reference to an element or value, while createRef is a method that returns a new ref object on every render. useRef in Function Components With the introduction of hooks in React, the useRef hook allows function components to create refs. createRef() for creating refs. Jun 18, 2022 · How to properly set focus to a div element in React using createRef Asked 2 years, 11 months ago Modified 2 years, 11 months ago Viewed 199 times Apr 15, 2020 · I am using library to write test cases for my application. React automatically updates the DOM to match your render output, so your components won’t often need to manipulate it. Jun 22, 2018 · Forwarding Refs Forwarding refs and higher-order components Conclusion React. Nov 15, 2022 · Learn how to use the React. Refs can be used to modify a component’s behavior or to access the underlying DOM structure for animating or manipulating it. ReactJS useRef is a hook in functional components for referencing DOM elements or other values. js The current property is a property that React creates on our this. While React Sep 28, 2022 · In this guide, learn how to set focus on an element after JavaScript's React component renders it, using functional and class components. Oct 4, 2022 · I am trying to detect when user clicks on an arrow using the keyboard. Mar 4, 2010 · React not setting ref correctly, Uncaught TypeError: current. createRef () in class components. Create refs via callback or createRef(). Note: According to documentation: If you’re currently using this. createRef () and assign the resulting ref to an element. createRef (); const fieldFour = React. createRef() API for creating refs. emailInput reference object - this property stores a reference to our input element in the DOM. In this tutorial, we’ll provide an overview of refs in React, including an example of using them with functional components. refs. Whenever a state or prop changes the component is re-rendered. I found this Arrow Keys React react module. What is ref in button? Feb 8, 2020 · I am trying to create a react form that uses refs. Refs can then be assigned to an element with ref-attribute. Apr 19, 2016 · Here in the parent component we store the ref of each CustomTextInput with onRef property and when the submit button from keyboard is pressed we call the focus method of the next CustomTextInput and the focus method of CustomTextInput focuses the TextInput inside the child component. It does work when I te Jan 10, 2021 · Hello everyone! 👋 Lately, I have been working a bit with refs in functional components and decided Tagged with react, javascript. current with the input DOM node. createRef() を使用して作成され、 ref 属性を用いて React 要素に紐付けられます。 Ref は通常、コンポーネントの構築時にインスタンスプロパティに割り当てられるため、コンポーネントを通して参照が可能です。 Dec 31, 2023 · This example focus on input element in React with ref createRef and useRef useEffect example. When the ref attribute is used on a custom class component, the ref object receives the mounted instance of the component as its current. So just create a ref and stored it into some variable and assign this variable to ref prop of DOM element. Learn how to create a ref with useRef or React. createRef() method that is used for initializing a ref value in class components. One of them is the Refs API. createRef () Refs can be created by using the React. createRef (); const fieldTwo = React. App. Imported { Ref } from ‘semantic-ui-react’ (it will wrap around our Semantic UI component and let us add a ref to it) — see line 3 Nov 26, 2018 · React同样支持另一种名为“回调refs”的方法去设置refs——它可以给我们对refs创建和销毁更细粒度的控制。 放入一个函数,而不是一个由createRef ()创建的ref属性。 这个函数接受React组件实例、或者HTML DOM元素作为参数——可以被储存并且在其他地方被访问。 Mar 7, 2024 · In React Native, “ref” (short for reference) is an object that provides a way to reference a React element or a DOM node created by a React component. createRef () receives the underlying DOM element as its current property. Refs provide you with a cool alternative when the child is a DOM element or an instance of another React component. Our solution will be focusing on two key methods of react, createRef and more recently, the react hook useRef. createRef () but getting error: TypeError: Cannot read property 'focus' of null Asked 5 years, 2 months ago Modified 5 years, 2 months ago Viewed 2k times To focus on a text field right after a React component renders, use refs in either function components (useRef) or class components (createRef). Aug 10, 2022 · What are React Refs? React Refs provide access to DOM nodes or React elements created in the render method. Creating Refs Refs are created using React. Traditionally, manipulating the DOM directly would be counterintuitive in React's declarative paradigm. bind(this)) } handleSubmit Sep 24, 2021 · I have an issue with focusing the next input in React Native. Then in render, I use an if statement to check whether the boolean is true, and call inputRef. createRef can be used in both class and functional components. createRef() in the constructor and assign the ref to the <input> through its props. Jul 12, 2023 · Conclusion Understanding the distinction between useRef and createRef is crucial when working with React. Now you can access the <input> ’s DOM node and call methods like focus(): Jan 21, 2020 · Written by Jeremias Menichelli ️ In this article, we’re going to investigate why React, a framework Tagged with react, javascript. The ref points to a number, but, like state, you could point to anything: a string, an object, or even a function. Ref を作成する Ref は React. Jun 18, 2022 · How to properly set focus to a div element in React using createRef Asked 2 years, 11 months ago Modified 2 years, 11 months ago Viewed 199 times Jul 12, 2023 · Conclusion Understanding the distinction between useRef and createRef is crucial when working with React. createRef() method and useRef Hook in React to simplify creating refs and interact with the HTML DOM. They are useful for handling focus, animations, measuring elements, and integrating with third-party libraries. In this blog, we'll look at React useRef in class component and compare it with useRef in functional components. Jul 23, 2025 · To use refs in React with TypeScript, you can take advantage of the ref attribute to directly interact with DOM elements or child components. Trying to use React. Discover use cases, best practices, and how to avoid common pitfalls when working with refs.