READ THE FUCKING MANUAL!
read the FRIENDLY manual.
Sorry for swearing, I'm not the one who came up with that. But it rings true.
Instead of fighting your code and assuming you already know how to code something based off previous experience, go read the docs (manuals).
Here is why. You may have already studied up on something and might even be using it daily! But sometimes you learn something with an assumption that was incorrect, yet due to how you were using it, it just worked.
Then you come to an issue and you waste hours trying to make it work, since last time you got it to work! Banging your head against the keyboard. You google everything you can... but why not just go to the source of truth?
I am sooooooooo guilty of this, it's why I'm writing this post. It's more of me calling myself out so I stop doing it!
Take Jest for an example. We use it for our unit test in every project. But for what ever reason, I struggle mocking classes every time. I think I remember how to do it, just to spend hours fiddling with the right solution.
Part of the issue is the time in between projects, but mostly due to me going off my assumption that I know what I'm doing based off that I got it working last time.
Well this time, I decided not to fight it. I read the docs. And sure enough I was wrong on what I thought it was doing.
So do yourself a favor. Before going off aimlessly for hours, go to the source of truth and confirm you know exactly what you need to do and how it works.
I hope this saves you hours of your life!