Questions tagged [create-ref]
28 questions
4
votes
2 answers
What are the advantages for using useRef or createRef rather than inline ref?
I was doing a code review and found the code written by another developer such as:
function sampleComponent() {
let divRef = {};
return (
{ divRef = el }}>
)
}
And then use the divRef as…
Kevin Moe Myint Myat
- 1,916
- 1
- 10
- 19
4
votes
1 answer
React using forwardRef always update child component even using memo
So I have a DatePicker ChildComponent that I need to access its ref via forwardRef from the Parent. Basically everything works fine.
But there's one problem.
Each time I update something on the Parent Other ChildComponents that has no any relation…

joyce
- 165
- 3
- 12
3
votes
1 answer
How can I rewrite useRef with class component?
I need to fetch integrations info in JSON format and I need help converting useRef (functional component) to createRef(class component).
Functional component:
import { createTTNCClient } from '~/shared/clients/ttnc';
const DevicesTable:…

Daria
- 83
- 1
- 8
2
votes
1 answer
Give ref to functional component to use inner functions
I have a Component let's say:
ParenComp.js
const ParentComp = (props) => {
const [isTrue, setIsTrue] = useState(false);
const setToTrue = () => {
setIsTrue(true);
};
const setToFalse = () => {
setIsTrue(false);
};
return isTrue ?…

Daniyal Shaikh
- 419
- 3
- 12
1
vote
0 answers
How to properly set focus to a div element in React using createRef
I have a react app that I am working on, and currently, I have a custom-built dropdown that I want to open/close when a user clicks on the trigger(the arrow button), close it when a user selects an option, or close it when a user clicks outside the…

Jordan kayinamura
- 13
- 3
1
vote
1 answer
Get anchor component by react ref, and update it's href field
I have a react code, where I have " < a > " component. When I click on "< a >", I want to change it's href field. For that, I have "ref" to get the component inside the "onclick" method like this:
class SomeComponent {
public ref:…

Mamuka Sakhelashvili
- 136
- 2
- 10
1
vote
1 answer
Function components cannot be given refs
I have the following problem:
I have ActionWeekModal which contains my own custom component called MList. Within this MList is a SwipeListView. I wanna use the reference of SwipeListView in ActionWeekModal to trigger the function scrollToEnd(). This…

Mees Maas
- 33
- 1
- 6
1
vote
0 answers
React forwardRef inside a loop
I'm trying to use react forwardRef to call a function inside bunch of child components. Here is the code.
const WorkoutFeedbackForm = ({
latestGameplaySession,
activityFeedbacks,
selectedActivityIndex,
setIsReady,
}) => {
const [isLoading,…

Malaka
- 314
- 3
- 12
1
vote
1 answer
How to access more than one element of Dom in react using React.createRef()
I know how to access single element of dom using React.createRef().But I want to access two different element using createRef. I have seen some example on stackoverflow for accessing multiple elements dynamically but unable to understand.I am…

Kanekar
- 161
- 1
- 14
1
vote
0 answers
React.createRef :current is null in Internet Explorer but works in other browsers
I am trying to use React.createRef
Current code works in Chrome, Firefox, Safari, Edge but in IE this.calendarRef.curent is null
constructor(props) {
super(props);
element = this;
this.state= {
allDayText: 'All day',
…

Takhtak Team
- 131
- 1
- 2
- 10
1
vote
1 answer
Why behavior is different?
What's the difference between createRef and ref={(c) => this.el = c}?
When I output each ref has same element but it not false.
why?
import React from "react"
class Home extends React.Component {
constructor(){
super();
this.el1 =…

Naoya
- 77
- 2
- 9
0
votes
2 answers
Ref current is ready only in class component
I am using a ref created using createRef to store a string value in a class component. However, whenever I try to change the value of current, I get the error that current is ready only. I am using typescript:
class MyClassComponent extends…

Saad Farooq
- 39
- 1
- 8
0
votes
1 answer
Why not use own object with current property rather than createRef in ReactJs
In ReactJs documentation, it is said
Refs are created using React.createRef() and attached to React elements via the ref attribute
Logging the ref gives an object which has a current property set to null. Just out of curiosity, I created a normal…

user31782
- 7,087
- 14
- 68
- 143
0
votes
2 answers
Is there a hook/method etc. in NextJs that is equivalent to the createRef() hook in original ReactJs?
I am trying to use 3rd party package ReactPhotoSphereViewer in NextJs to display panoramic images in the website.
The package works both in NextJs and in ReactJs.
Here is the code that is works in ReactJs:
import { ReactPhotoSphereViewer } from…

Yusuf Arslan
- 21
- 3
0
votes
1 answer
How to use createRef to toggle Accordion list items
I have a FlatList and each item is an accordion, I m using class based react and I want to be able to toggle each accordion individually using createRef but I was unsuccessful
export default class shopingScreen extends React.component{
…

Rihab sabri
- 301
- 2
- 16