Uncaught Error: Expected `onClick` listener to be a function, instead got a value of `string` type

Viewed 37

Hello i'm currently making my programm dynamically. This static code is working perfect;

      <Step name="question1">
        <div className="stepContent">
          <h4>Are you visiting Berlin alone?</h4>
          <Controls>
            {({ destinations: { question2, question3 } }) => (
              <div className="buttonContainer">
                <button onClick={question2}>Yes</button>
                <button onClick={question3}>No</button>
              </div>
            )}
          </Controls>
        </div>

But my dynamic code is causing this Uncaught Error: Expected onClick listener to be a function, instead got a value of string type. Error

        <div className="buttonContainer">
          {block.nextTag.map((step, index) => (
            <Controls>
              {(destinations = step) => (
                <button onClick={step}>
                  {block.nextTagDesc[index]}
                </button>
              )}
            </Controls>
          ))}
        </div>

Thanks for help. If you need additional information just comment.

1 Answers

The error says answer at all you must have to pass function in your check the type of your "step" variable with typeof(step)

your function would be returning string try to pass a function inside your onclick

Related