I’m trying to save my states into the cookies using the react-cookie package. It’s ok when I want to store some strings into the cookie but my problem is when it comes to saving arrays. For example, I have an array with the below structure:
const arr = [
['correct','correct','absent'],
['present','correct','present'],
['absent','absent','correct']
]
And now I want to store it into the cookie with the below code:
setCookie("states",arr);
When I tried to get states from the cookie with cookies.states I just got an object with correct,correct,absent,present,correct,present,absent,absent,correct result.
Here is my question:
How can I store a 2-dimensional array into cookies and get it with array type?
>Solution :
If it works well with strings did you try to stringify it before saving ?
setCookie("states", JSON.stringify(arr));