Skip to content

NextJS prefetch functionality? #3052

Answered by J4v4Scr1pt
J4v4Scr1pt asked this question in Help
Discussion options

You must be logged in to vote

I have spent a couple of hours now to search and test. We can user router.prefetch(item.href); But when the component re-renders for some reason. It triggers the prefetch again. We could use memoization etc.. but nahh..

Then.. I realized the as prop.. NextUI shows once again why its the best UI-lib.

This is how I solved it with the ListBoxItem for the sidebar, works as expected and it prefetch in production.

	<ListboxItem
			as={item.href ? Link : 'li'}
			{...{ ...item, href: undefined }}
			href={item.href || undefined}
			key={item.href || item.key}
			aria-label={t(item.key)}
                        ..................

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by J4v4Scr1pt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant