Peter
Peter

Reputation: 11

How can I do to do many things in a tag?

Hello I have this button using React.js :

<button className="btn btn-outline-success btn-block"
 type="submit" onClick={props.onClose}  >

It works perfectly but I would like to do other things that only apply the onClose function. So I try that :

<button className="btn btn-outline-success btn-block"
 type="submit" onClick={closewindow()}  >

and I defined the function closewindow like that :

const  closewindow = () => {
      props.onClose
  }

But I got that : Expression statement is not assignment or call

Do you know how can I do to solve that ?

Thank you very much !

Upvotes: 0

Views: 17

Answers (2)

CoderCharmander
CoderCharmander

Reputation: 1910

As @Anton said, you have to remove the () from the handler (onClick={closewindow}). You also have to add () to the function definition:

const closewindow = () => {
    props.onClose(); // () here (optional semicolon)
};

Upvotes: 1

Anton
Anton

Reputation: 61

Please try to remove () like this in onClick handler.

<button className="btn btn-outline-success btn-block"
 type="submit" onClick={closewindow}  >

Upvotes: 0

Related Questions