Home > Software engineering >  Best way to store and persist cart data in react native?
Best way to store and persist cart data in react native?

Time:08-17

Options:

  1. via API in our database
  2. RealM database to store locally
  3. Local Storage

CodePudding user response:

The best answer will be it depends on your scenario.

If the data is just the product information which a user wants to buy i.e. add to cart then i would suggest to use a storage option which is available to read, edit and gets deleted instantly and that would be the use of any state management eg. redux or using realM / sqlLite.

It is just a cart on front-end so i don't think it will contain any critical information. you can avoid the api calls as it will a little more time consuming.

In an e-commerce scenario where a user is adding some product in a wish-list or in a cart , the time taken to do CRUD operation is very critical as it will decide the user's buying experience.

if you think you need that information (wish-listed products ,products in the cart) you can later run a CRON job or something to save it in your db.

CodePudding user response:

It all depends on how critical is your cart data,

For suppose if the user adds something in cart and you want to know which all products are crucial to user, and suppose if you have a web app and mobile app, then it should be same, then your 1st option is the best way to go about it.

For suppose if its a device only app, then storing it in DB makes more sense . Local storage is anyways not efficient.

Hope it helps, feel free for doubts

CodePudding user response:

The most efficient way is to check with API to persist across multiple devices.

  • Related