Ferinecko
Ferinecko

Reputation: 19

Why one function fires but the other one dosn't? [React]

Working in ReactJS

I have a button that toggles a section but I want also to auto scroll to that section, I have a fixed nav so I need to also offset the scroll.

I can't make 2 calls work in side onClick:

onClick={handleClick, ()=>{ setToggle(1)}}

this way setToggle function runs but handleClick doesn't.

any help appreciated!

Upvotes: 1

Views: 28

Answers (1)

Priyank Kachhela
Priyank Kachhela

Reputation: 2635

Try to call methods like below:-

onClick={(event) => { 
   handleClick(event);
   setToggle(1);
}}

Upvotes: 3

Related Questions