use ref

 

useRef in React vs Refs in Vue

  • React’s useRef is used to create a reference to a DOM element or a value that doesn’t trigger re-renders when changed.
  • Vue’s ref directive also lets you directly access DOM elements or store values that don’t cause reactivity when changed.

Example in Vue:

html
<template> <input ref="myInput" /> </template> <script> export default { mounted() { this.$refs.myInput.focus(); // Directly access DOM element } } </script>
=
useRef in React vs. Refs in Vue
React’s useRef to access a DOM element or store values:

javascript
Copy code
import { useRef, useEffect } from 'react';

function MyComponent() {
  const inputRef = useRef(null);

  useEffect(() => {
    inputRef.current.focus(); // Focus the input on mount
  }, []);

  return <input ref={inputRef} />;
}
Vue equivalent:

html
Copy code
<template>
  <input ref="myInput" />
</template>

<script>
export default {
  mounted() {
    this.$refs.myInput.focus(); // Directly access DOM element
  }
}
</script>

=

No comments:

Post a Comment

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...