3 Random JavaScript Tips You Should Apply In Your Project

İlyas Akın
2 min readSep 14, 2022

1- Only store the data that you need in the store

It doesn’t mean you need to store everything in your store because you are using a store. Let me give some examples to make this clear;

You should store these in your store; currencies, countries, the current user… in short, any static data that doesn’t need to be updated constantly.

You shouldn’t use the store for; Any data specific to a page, for example, let’s say we have a page that lists users. We don’t need to store that data in the store because it will be changed or refreshed anyway by the next time we visit the page.

Furthermore, using the store for something that you shouldn't use the store for complicates a simple process. Adds an extra layer that shouldn’t even be there in the first place.

2- Implement libraries into your services

So, I see loads of projects that expose dependencies to the entire application. Take Axios for example. You can expose Axios everywhere, and, it’ll work perfectly. But, what if you need to migrate to another HTTP request library? Or, what if Axios releases a new major version and changes everything? In this case, you need to update every Axios usage in your application.

Here is what you should do instead;

Wrap the Axios into a HttpService, and expose some standard methods there, like get, post, patch… etc. And don’t use Axios directly anywhere else if you don’t have to.

Here is the example HttpService.

3- Don’t cram everything in your helper service.

Helper services shouldn’t be a generic method mess. Methods in the helper services shouldn’t contain any business logic whatsoever. If your method contains business logic, you should probably divide your method and have that part that contains business logic in the other related service. Helper services can be dangerous and can give you headaches when you abuse them.

Don’t forget to follow if you want to see more tips/best practices for JavaScript/TypeScript.