Share
When do you use refs in ReactJS?
Question
- Refs are created using React.createRef().
- Refs are attached to input elements using the ref attribute on the element in
- question.
- Refs are often used as instance properties on a component. The ref is set in the constructor (as shown above) and the value is available throughout the component.
- You cannot use the ref attribute on functional components because an the instance is not created
- React.createRef() is used to create instance variables within uncontrolled component constructors. These variables are then associated with input elements via the ref attribute.
- Refs cannot be used on functional components as there is no instance.
- Refs can be used inside functional components
Leave an answer