I feel like this some some interpretation of the classic “Impostor Syndrome”.
Basically every dev has the fear of not being good enough, or not learning enough. (Unless they are the opposite)
So “Why should I learn this if I’m going to forget”, or “Why should I continue, I won’t get able to get it later”, all is because of the same mentality I’m not good enough.
So if you feel like this sounds like you, defiantly look into other stories of people experiencing similar feelings. (there’s A LOT)
Now for how I get over the feeling of not being motivated comes down to challenging myself more, and focusing on smaller somewhat challenging tasks.
Doing a project that sounds interesting usually works, do what you know you can accomplish, refine what you already know and mix in somethings you don’t. Give yourself confidence you can do something with what you have learned, and go out see what else you can learn that you want to learn.
Like anything else you need to practice to get better. Laying off for weeks wont work, you must be more consistent otherwise you will forget and you wont succeed. There isn’t an easy way around that fact, you have to be consistent to get things into muscle memory, and even then you need to keep using what you learned to help you remember.
Going back to what I said about a project, do something challenging enough to keep you interested, open enough so you don’t have to grind through something super complicated, and straight forward enough that you can see it from the start to the end.