Can anyone tell me how to avoid on click error in react js

124 views Asked by At

Expected onclick listener to be a function, instead got a value of string type. getListener@http://localhost:3000/static/js/bundle.js:18256:15 accumulateSinglePhaseListeners@http://localhost:3000/static/js/bundle.js:22846:39

<button onClick={Window.href='https://github.com/'} className="btn btn-github" >

I am using react js. During on click event shows the above error tell me how I can solve it I will be very glad? My on click event is not working while using react.

2

There are 2 answers

0
Raed On

Try doing this :


onClick={() => {window.href='https://github.com/'}}
0
kind user On

Expected onclick listener to be a function, instead got a value of string type.

As the error states, the onClick handler expects a function, not a string. Just wrap your sample with a function call.

onClick={() => {
   Window.href = 'https://github.com/';
}}