Use Context and an API Client handling a token from storage

Viewed 98

I'm currently working on a project in which I can fetch datas after a user has logged in.

I want the token to persist even after a reload of the page or when the user returns.

I also wanted to implement the useReducer for my fetch actions and use it inside one or multiple contexts to manage the data of my app.

Knowing that, I have some questions :

  • Do I code my fetches in an ApiClient file, which then gets called upon the dispatch of certain actions ? Or do I put every call inside a function in my context ?

  • How do I manage the storage of the token ? In my ApiClient or in my initalState of the context ?

  • What about splitting my data in multiple contexts sharing the same base user context ? Or do I do one huge Context ?

Thanks in advance for the answers / discussions, do not hesitate if you need more informations.

Regards

0 Answers
Related