React API Call Best Practice
Published in
1 min readJul 10, 2020
Are you tired to call API in every react component? Let me show you how I build a reusable api calling service in react.
I always have a folder called helper and a file called “api.js” inside it. You may name it or locate it as you like.
You have your own way to get the cookies right?
Having this saved as api.js, you can call it easily from other component. It also make you easy to reuse it in other component. Let me give you a simple example.
So, anytime you need to call certain API, you don’t need to write it in every page of your component, you can just call api.js and use easily.
Happy coding.