Bootstrap 5 Popovers with React

Viewed 23

I am trying to add Bootstrap 5 popovers in React. I am not using any React-Bootstrap library. Per the Bootstrap documentation, I have added the initialization code, but I am getting these two errors. Can anyone help?

enter image description here

1 Answers

Both of these errors are related to restrictions of TypeScript. In order to solve the first error, I would suggest you use a for loop instead of using map like:

for (let i = 0; i < popoverTriggerList.length; i++) {
  const popoverTriggerEl = popoverTriggerList[i];
  new bootstrap.Popover(popoverTriggerEl);
}

In order to solve the second error, I would suggest you declare a bootstrap variable like:

declare var bootstrap: any;

You can take a look at this sandbox (bootstrap included by cdn) or this sandbox (bootstrap included by npm) for a live working examples of these usages.

Related