Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next.js 13 example with Experimental App Directory #838

Open
TrueXPixells opened this issue Jun 15, 2023 · 3 comments
Open

Next.js 13 example with Experimental App Directory #838

TrueXPixells opened this issue Jun 15, 2023 · 3 comments
Labels
🧡help wanted 🧡 Extra attention is needed

Comments

@TrueXPixells
Copy link

TrueXPixells commented Jun 15, 2023

Can u make about example of (title*)? It would be happy when pushed to examples folder, i need it too much, i cant code without app directory ❤️ and good library

@jmyrland jmyrland added the 🧡help wanted 🧡 Extra attention is needed label Jun 15, 2023
@jmyrland
Copy link
Collaborator

Hey @TrueXPixells ! Sounds like a good example to have. In theory, it should not be very different from the traditional next setup.

Reading the docs, it seems that the root layout will be replacing the old _app.jsx. If I understand correctly, the <StoreProvider store={store}> should be placed inside your root layout.jsx.

Haven't tested the new app structure with Next.js yet, but if you get an example up and running - feel free to submit a PR with the new example 👍

@Syed-Sheharyar
Copy link

Syed-Sheharyar commented Jul 11, 2023


import { StoreProvider as EasyPeasyStore } from "easy-peasy"
import store from "../../store"
import { ReactNode } from "react"

export default function StoreProvider({ children }: { children: ReactNode }) {
  return <EasyPeasyStore store={store}>{children}</EasyPeasyStore>
}

// First, you must make a client component for EasyPeasyStore and then import your StoreProvider in the root layout.(jsx|tsx) file. With this, you have a working store. Edit "Devtools just work fine as well" I myself use this approach for a huge project so, it works. See layout.tsx file

```import "./globals.css"
import { Inter } from "next/font/google"
import StoreProvider from "../components/core/StoreProvider"

const inter = Inter({ subsets: ["latin"] })

export const metadata = {
  title: "Create Next App",
  description: "Generated by create next app"
}

export default function RootLayout({
  children
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body className={inter.className}>
        <StoreProvider>{children}</StoreProvider>
      </body>
    </html>
  )
}

// You need to use EasyPeasyStore in a client component because it uses React Context under the hood and it's not available server side. I imported my custom StoreProvider which uses EasyPeasy StoreProvider under the hood.

@jmyrland
Copy link
Collaborator

I didn't know that contexts were unsupported in Next.js 13. I can't seem to find an alternative to contexts, so creating your own client Store-component seems to be the approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧡help wanted 🧡 Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants