0
1

More than 1 year has passed since last update.

js-cookieのパッケージをバージョンアップ(v3)したらgetJSON()が使えなくなっていた

Posted at

v3から削除された見たいです。

Removed built-in JSON support, i.e. getJSON() and automatic stringifying in set(): use Cookies.set('foo', JSON.stringify({ ... })) and JSON.parse(Cookies.get('foo')) instead.

組み込みオブジェクトメソッドを使いましょうとのことです。

before.ts
import { set, getJSON } from "js-cookie";

// save json to cookie
const data = { /* なにかオブジェクトを */ };
set(JSON.stringify('some-key', data));

// load json to cookie
const dataFromCookie = getJSON(key);
after.ts
import { set, get } from "js-cookie";

// save json to cookie
const data = { /* なにかオブジェクトを */ };
set(JSON.stringify('some-key', data));

// load json to cookie
const dataFromCookie = JSON.parse(get(key));
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1