Created
July 4, 2022 09:42
-
-
Save davivieira/c1118936f6baa4b7669b4e6357b7cd12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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