The default export is not a React Component in page: “/” NextJS

Date: 23/01/2021 I’ve also faced this issue on my Next.js app. If you’re using a functional component instead of a class component you’ll get this error as well in some casses. Exactly I don’t know why this is happening but I just resolved this issue by exporting my component at the bottom of the page. … Read more

How can I manually compile a svelte component down to the final javascript and css that sapper/svelte produces?

Ouch, tough one. Hang tight. What you’re missing actually is the “linking”, that is resolving import statements in the compiled code to something the browser can use. This is the work that is typically done by the bundler (e.g. Rollup, Webpack…). These imports can come from user (widget developer) code. For example: import { onMount … Read more

Next.js Opt out of Layout Component for specific pages from _app.js

by checking the appProps.router.pathname property passed to it. way 1 function MyApp({ Component, pageProps, …appProps }: AppProps) { // make function that will return the children based on router.pathname const getContent = () => { // array of all the paths that doesn’t need layout if ([`/dashboard`].includes(appProps.router.pathname)) return <Component {…pageProps} />; return ( <Layout> <Component … Read more

Error: How to serialize data from getStaticProps : Next.js

Add JSON.stringify when calling an asynchronous function that returns an object. Try modifying your getStaticProps function like this. export async function getStaticProps() { const profiles = await getAllBusinessProfiles(); const allProfiles = JSON.stringify(profiles) return { props: { allProfiles } }; } The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing … Read more

Dynamic routing with getServerSideProps in Nextjs

export async function getServerSideProps(context) { const { id } = context.query; const res = await fetch(`https://restcountries.eu/rest/v2/name/${id}`); const country = await res.json(); console.log(`Fetched place: ${country.name}`); return { props: { country } }; } you are returning a nested object from above function { props: { country:country } } so this prop will be attached to props … Read more

NextJS 13 folder structure best practice

I think reading this section in Next docs helps you organize the project folders: https://nextjs.org/docs/app/building-your-application/routing/colocation I tried with many different structures and I finally chose this one: Everything (all folders and files) will be in the /app directory because the /app directory accepts colocation and it’s different from /pages directory which was only for routing … Read more

How to get query params using Server component (next 13)

I don’t think it’s currently possible to do this in an arbitrary component. However, it is possible to access query parameters in page.tsx files, and pass these down to your components via props. export default function Page({ params, searchParams, }: { params: { slug: string }; searchParams?: { [key: string]: string | string[] | undefined … Read more