最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use bootstrap popover with reactjs - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question asked Jul 23, 2018 at 20:07 Roy SalibaRoy Saliba 531 silver badge5 bronze badges 2
  • Checkout reactstrap: reactstrap.github.io/ponents/popovers – Pop-A-Stash Commented Jul 23, 2018 at 20:11
  • Or React-Bootstrap react-bootstrap.github.io/ponents/popovers – lsimonetti Commented Jul 23, 2018 at 20:20
Add a ment  | 

2 Answers 2

Reset to default 3

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

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

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 ponent

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

Make sure you import jquery top of the file

import $ from 'jquery'
发布评论

评论列表(0)

  1. 暂无评论