Skip to content

Instantly share code, notes, and snippets.

@davivieira
Created July 4, 2022 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davivieira/c1118936f6baa4b7669b4e6357b7cd12 to your computer and use it in GitHub Desktop.
Save davivieira/c1118936f6baa4b7669b4e6357b7cd12 to your computer and use it in GitHub Desktop.
import { createSignal, createResource } from "solid-js";
import { createMutable } from "solid-js/store";
export const list = createMutable({
items: JSON.parse(
window.localStorage.getItem("cart") ?? "[]"
),
get count() {
return this.items.length;
},
addItem(item) {
this.products.push(item);
},
clear() {
this.items = [];
},
});
export const [count, setCount] = createSignal(0);
export const [items] = createResource(
() => fetch("your api ...").then((res) => res.json()),
{
initialValue: [],
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment