perf: not indexing every render

This commit is contained in:
Artemy 2023-04-07 13:25:27 +03:00
parent 0b7523c57d
commit 548b2955cd

View file

@ -22,12 +22,11 @@ function Notes() {
let n = Object.values(localStorage.getObj("Notes")); let n = Object.values(localStorage.getObj("Notes"));
let [search, setSearch] = useState(""); const [search, setSearch] = useState("");
const [indexed, setIndexed] = useState(false);
let fuse; if (search && !indexed) {
window.fuseIndex = new Fuse(n, {
if (search)
fuse = new Fuse(n, {
includeScore: true, includeScore: true,
useExtendedSearch: true, useExtendedSearch: true,
keys: [ keys: [
@ -39,8 +38,10 @@ function Notes() {
}, },
], ],
}); });
setIndexed(true);
}
let found = search === "" ? n : fuse.search(search); let found = search === "" ? n : window.fuseIndex.search(search);
if (search !== "") { if (search !== "") {
found = found found = found