Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!