3

I have tried to follow the bootstrap documentation to make work a popover. But I have been unsuccessful in converting this piece of code into something React can understand.

   {
  $(document).ready(function() {
    $('[data-toggle="popover"]').popover();
  });
}

Without it my popover cannot function properly. What's the solution?

Roy Saliba
  • 53
  • 1
  • 5

2 Answers2

3

Also you can do that too, if you define jquery in index.html. Call jquery from window object.

componentDidMount() {
    window.$('[data-toggle="popover"]').popover();
}
musti
  • 31
  • 1
  • 1
1

It make sense to use react-bootstrap library but if you still want a solution go ahead and follow this...

You need to understand react lifecycle methods instead of using document.ready callback function.

try adding this to your react component

componentDidMount() {
    $('[data-toggle="popover"]').popover();
}

Make sure you import jquery top of the file

import $ from 'jquery'
webgoesviral
  • 345
  • 2
  • 8