Sabbagh's Blagh
The Software blog of a Development Journeyman

NextJS TIL (updated regularly)

August 23, 2022

tagged: react, nextjs

What's Next?

This is a collection of TILs for NextJS, a pretty awesome React Framework. You can read about it here.


8/23/2022

I was using this to manage page navigation changes on danielsabbagh.com:

const [isLoading, setIsLoading] =  useState(false); 

Well, because NextJS is so great at client-side routing, I can key off of the router's asPath to manage page changes:

const dynamicRoute = useRouter().asPath;

...
 // clear related posts when loading new blog post
useEffect(() => {
  setRelatedPosts([]);
  setShowRelatedPosts(false);
  setPostLikes(0);
  setTag('');
}, [dynamicRoute]);

With this, I blew away the isLoading silliness!

© Copyright 2024 Sabbagh's Blagh. Powered with by CreativeDesignsGuru