S
S
Sergey2021-01-28 13:20:12
JavaScript
Sergey, 2021-01-28 13:20:12

How to write sequentially to cookies?

Hello. colleagues!

It is necessary to write the product id in cookies sequentially separated by commas each time you visit the product page.

Cookie example:
We went to the page of 2 products, in the end it should be
products_track='1984,8542'

Add a function inside the component that gets the old values ​​from cookies, adds a new product ID to the existing one, but when rendering everything is overwritten and only the current product ID is always written. Can someone tell me where and in what place should the cookie be written so that the value is not overwritten, but added sequentially?

Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
turbolizard, 2021-01-28
@turbolizard

In general, it’s probably not cookies that suit you better, but Local Storage for such purposes, especially since it’s customary to store such things in various structures there. Regarding the overwriting: most likely you do not check for the presence of already set cookies, or take out the function and make it asynchronous with await receiving and writing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question