How to save JSON in the cookie? Right now I can only save a string in cookie using this library!
Closed this issue · 1 comments
saigita commented
import Cookie from 'mobx-cookie';
import User from '../interfaces/User';
type SetUserHandler = (user: User) => void;
interface SessionStore {
user: User;
setUser: SetUserHandler;
}
class SessionStoreImpl implements SessionStore {
cookie = new Cookie("user");
setUser(user: User) {
this.cookie.set(user);
}
get user() {
return this.cookie.value;
}
}
export default SessionStoreImpl;
Not able to set user in cookie, it expects a string
will-stone commented
Indeed, because cookie values are strings (small amounts of text). Here's a good article about cookies.