SoFunction
Updated on 2025-04-13

Five ways to get DOM elements in react component

1. Set the ref attribute for the tag and call it through this.refs (the old version of syntax will be abolished)

2. Binding the function in the tag ref attribute, define the global variable assignment in the function, and call it through the global variable

3. Use hook syntax to find DOM

4. Create a ref global variable in the constructor, dynamically bind the ref attribute in the tag, and call it through the current field of the global variable.

5. Use hook syntax to find DOM