skip to Main Content

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

onClick={Window.href=’https://github.com/’}
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

Answers


  1. Try doing this :

    
    onClick={() => {window.href='https://github.com/'}}
    
    Login or Signup to reply.
  2. 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/';
    }}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search