80 likes | 92 Views
Refs make possible to access Dom nodes directly within react. Suppose you want text input to be focused in Form so achieve it with Refs. So create new file refs.js. In file use input element. It can be done in three simple steps.<br><br>https://www.ducatindia.com/javatraining/
E N D
Language | Industrial Training | Digital Marketing | Web Technology | Testing+ | Database | Networking | Mobile Application | ERP | Graphic | Big Data | Cloud Computing Welcome to ducat india React Refs 7070905090 info@ducatindia.com
React Refs Refs make possible to access Dom nodes directly within react. Suppose you want text input to be focused in Form so achieve it with Refs. So create new file refs.js. In file use input element. It can be done in three simple steps. First step is to create Ref using react ref method. So in this component add constructor within constructor create new property ‘this.inputref’. To this property assign react.createRef(). Second method is to attach ref to input element in render method. Third method is to call focused method into this element as-:
As output is as below where first message arrives and when you click OK, then the form will be shown of number increment.
As when you click on increment sign again message arrives and after click OK again , only then number will be increment.
On button click access “ref” function which is created in following code and you can increment the value without rendering component again and again. When ref is pass to element that element is accessible using an attribute call as current.
So here this.quantityRef method is used where element is accessible through ref. componentDidMount(){ this.usernameRef.current.focus();
THANK YOU React Refs 7070905090 info@ducatindia.com