In React, unlike working with vanilla JavaScript, accessing DOM elements directly is different. React uses a virtual DOM to efficiently update the real DOM, this makes it different from vanilla JavaScript.
Option 1: Using Refs
Option 2: Using React.createRef (v16.3 )
Option 3: Using Callback Pattern (Legacy)
Option 4: Using String Refs (Legacy)
Below is an example of using the callback pattern to select a DOM element:
render() { return (To access the elements, you can use this.progressBars[0], this.progressBars[1], and this.progressBars[2] to perform operations on them.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3