0

The problem here is that whenever I open the page. the link is automatically opens, sometimes it opens 3 new windows without clicking the div

<div onTouchTap={window.open(a)}> TEST </div>

can you please provide your input? or suggest any other alternatives. by the way I am using ReactJS

dczii
  • 539
  • 5
  • 10
  • 20

2 Answers2

1

You need to provide a function to the onTouchTap, you are actually executing window.open(a).

You could do something like:

<div onTouchTap={() => window.open(a)}> TEST </div>

I describe a similar solution and some of the caveats in another answer:

https://stackoverflow.com/a/37771414/350933

Community
  • 1
  • 1
ctrlplusb
  • 12,847
  • 6
  • 55
  • 57
0

It's very common mistake. There must be a function () => {window.open(a)} or window.open.bind(null, a) as onTouchTap handler, but you are trying to put function call here, so it calls every time when your div rendering

Vitaly Kravtsov
  • 960
  • 5
  • 18