Great article. But I have this strange feeling that the code would have been slightly easier to read if it didn’t use hooks. I say that because there’s nothing about the code that tells me that your button is stateful. And it is in fact stateful because it literally relies on side-effects (or in React parlance “useEffect”). However we can’t tell that because (a) button is a function component which makes me think it’s stateless and (b) the function that uses useEffect abstracts that away inside of useClick.
tl;dr: if this was a class component then it would be clear that the component is stateful.
That being said, bravo on the testing code! :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article. But I have this strange feeling that the code would have been slightly easier to read if it didn’t use hooks. I say that because there’s nothing about the code that tells me that your button is stateful. And it is in fact stateful because it literally relies on side-effects (or in React parlance “useEffect”). However we can’t tell that because (a) button is a function component which makes me think it’s stateless and (b) the function that uses useEffect abstracts that away inside of
useClick
.tl;dr: if this was a class component then it would be clear that the component is stateful.
That being said, bravo on the testing code! :)