Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
How can I Inject jQuery tooltip code into React via NPM or Hook?

jQuery code is injected in the root file of React project and now it needs to use via the NPM package. can anyone help me or give any suggestions?

<script>
  $(document).ready(function() {
    $("body").tooltip({ selector: '[data-bs-toggle=tooltip]', trigger : 'hover', html:true });
  });

  function hideTooltip() {
    $(".tooltip").hide();
  }
</script>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You don't. It is not recommended to use jQuery inside of a react application.

As React states in its documentation :

"Just because it’s possible, doesn’t mean that it’s the best approach for React apps. We encourage you to use React components when you can. React components are easier to reuse in React applications, and often provide more control over their behavior and appearance."

You can achieve this by simply using CSS (:hover & adjacent sibling selector)

You can also use a library which will do the trick for you, no need to reinvent the wheel

Here is a code sample to illustrate my words :

.tooltip-container {
  padding: 1rem;
  position: relative;
}

.tooltip-content {
  opacity: 0;
  visibility: hidden;
  
  background: #333;
  padding: 5px 10px;
  color: #fff;
  
  position: absolute;
  top: 0;
  left: 0;
  
  transition: all 0.3s;
}

.tooltip-hoverable:hover + .tooltip-content {
  opacity: 1;
  visibility: visible;
}
<div class="tooltip-container">
  <p class="tooltip-hoverable">
    Hover me
  </p>
  <span class="tooltip-content">I'm the tooltip</span>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

you could use import $ from 'jquery'; and useEffect/componentDidmount

import { createRoot } from 'react-dom/client';
import TodoList from './refs/TodoList';
import { useEffect } from 'react';
import $ from 'jquery';

const App = () => {
    useEffect(() => {
        $("body").tooltip({ selector: '[data-bs-toggle=tooltip]', trigger : 'hover', html: true });
    }, []) 

    return (
        <div>
            <TodoList />
        </div>)
};

const container = document.getElementById('root');
const root = createRoot(container!);
root.render(<App />);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda