What’s the difference between useRef and createRef?

Technology CommunityCategory: ReactWhat’s the difference between useRef and createRef?
VietMX Staff asked 3 years ago

The difference is:

  • createRef will always create a new ref. In a class-based component, you would typically put the ref in an instance property during construction (e.g. this.input = createRef()). You don’t have this option in a function component.
  • useRef takes care of returning the same ref each time as on the initial rendering.