First, it’s okay to feel confused and stuck while learning these sorts of things. In fact, it’s an important part of the process, feeling confused is often what happens before you learn something new. Working as a developer you have to get comfortable with heading into unfamiliar territory and facing problems that don’t have obvious solutions.
Sometimes the best thing to do is to step away from the code itself and instead try and think about the problem in a different way. Drawing out a representation of it on paper or a whiteboard, or writing out metaphors to describe it can all be useful for some people. Doing this can give the analytic part of your brain a bit of a rest and gives your subconscious some room to try and process the problem a bit further.
I also recommend going back and working on something that isn’t quite so challenging for you, but was challenging for you maybe a few days or a few weeks ago. Reviewing something like this can be a good way to see how far you’ve come in a short time and give you a bit of a confidence boost.