Reve
Reve
SSolidJS
Created by laksh on 7/9/2024 in #support
web-vitals integration
guessing lol I use astro so what I do is just put all that stuff in the script tag
29 replies
SSolidJS
Created by laksh on 7/9/2024 in #support
web-vitals integration
I guess you just put that in onMount?
29 replies
SSolidJS
Created by laksh on 7/9/2024 in #support
web-vitals integration
btw why am I here lol
29 replies
SSolidJS
Created by Reve on 7/9/2024 in #support
Implement 'load more' feature efficiently
This is my first time using Solid since most of the time I build backend libraries
17 replies
SSolidJS
Created by Reve on 7/9/2024 in #support
Implement 'load more' feature efficiently
I'm using Solid with Astro to build some sites
17 replies
SSolidJS
Created by Reve on 7/9/2024 in #support
Implement 'load more' feature efficiently
I saw it but never actually tried it
17 replies
SSolidJS
Created by Reve on 7/9/2024 in #support
Implement 'load more' feature efficiently
I learn faster by just looking at the docs lol
17 replies
SSolidJS
Created by Reve on 7/9/2024 in #support
Implement 'load more' feature efficiently
It works the same for all effect hooks like createEffect and createRenderEffect right?
17 replies
SSolidJS
Created by Reve on 7/9/2024 in #support
Implement 'load more' feature efficiently
btw what is untrack in your code?
17 replies
SSolidJS
Created by Reve on 7/9/2024 in #support
Implement 'load more' feature efficiently
The point is that I don't waste memory to create a new list though Btw here's my solution after a while props.list is the initial list passed from astro previously I will have to add onMount(loadMorePosts) to load initial posts
import { For, Show, createSignal } from 'solid-js';
import Post from './Post';
import getPosts from './getPosts';

export interface Props {
list: Post[] | undefined | void;
}

export default function Posts(props: Props) {
const [loadedPosts, setLoadedPosts] = createSignal<Post[]>(props.list ?? [], { equals: false });

async function loadMorePosts() {
const currentPosts = loadedPosts();

if (currentPosts.length === 0) {
const newPosts = await getPosts(-1);

if (typeof newPosts !== 'undefined')
setLoadedPosts(newPosts);
} else {
const newPosts = await getPosts(currentPosts[currentPosts.length - 1]!.id);

if (typeof newPosts !== 'undefined') {
currentPosts.push(...newPosts);
setLoadedPosts(currentPosts);
}
}
}

return (
<div class='min-h-screen'>
<div class='grid grid-cols-1 gap-12 mt-12'>
<Show when={loadedPosts().length !== 0} fallback={<p class='text-primary'>Loading posts...</p>}>
<For each={loadedPosts()}>{Post}</For>
</Show>
<button class='btn btn-primary' onMouseDown={loadMorePosts}>Load more posts...</button>
</div>
</div>
);
}
import { For, Show, createSignal } from 'solid-js';
import Post from './Post';
import getPosts from './getPosts';

export interface Props {
list: Post[] | undefined | void;
}

export default function Posts(props: Props) {
const [loadedPosts, setLoadedPosts] = createSignal<Post[]>(props.list ?? [], { equals: false });

async function loadMorePosts() {
const currentPosts = loadedPosts();

if (currentPosts.length === 0) {
const newPosts = await getPosts(-1);

if (typeof newPosts !== 'undefined')
setLoadedPosts(newPosts);
} else {
const newPosts = await getPosts(currentPosts[currentPosts.length - 1]!.id);

if (typeof newPosts !== 'undefined') {
currentPosts.push(...newPosts);
setLoadedPosts(currentPosts);
}
}
}

return (
<div class='min-h-screen'>
<div class='grid grid-cols-1 gap-12 mt-12'>
<Show when={loadedPosts().length !== 0} fallback={<p class='text-primary'>Loading posts...</p>}>
<For each={loadedPosts()}>{Post}</For>
</Show>
<button class='btn btn-primary' onMouseDown={loadMorePosts}>Load more posts...</button>
</div>
</div>
);
}
Can you check if there's any problem here
17 replies