Next.js 13 Redux Toolkit Tutorial

Поделиться
HTML-код
  • Опубликовано: 28 дек 2024

Комментарии • 105

  • @GabrielGasp
    @GabrielGasp Год назад +60

    For those left with the question: "Isn't this messing up the whole SSR thing" or "Now that there is a client component wrapping the entire application, isn't it forcing all components to act as client components", read along.
    This is not actually the case, server components are only handled as client components when they are directly imported and rendered in a client component (that has 'use client'). In this implementation they are not actually imported, but received as children. When you do this, the `{ children }` acts as a "hole", it's not rendered there but in the parent component and then passed (as children) to "fill the hole".
    This is a bit confusing but is in the docs, look for "Nesting Server Components inside Client Components" in the "React Essentials" section.
    You can confirm this pretty easily, follow the video and wrap the layout children in the Redux provider. Now, leave the page.tsx file as a server component (no 'use client') and add a console.log to it. Notice that the log only happens in the server, not in the browser console, this is because the component is still handled by the framework as a server component. Or you can just install and add the "server only" directive at the top of page.tsx and confirm that you are not getting any errors ¯\_(ツ)_/¯.
    Also, you don't have to add "use client" in every redux file, only in the provider.
    Fun fact: Next.js is already using redux under the hood, if you have the Redux DevTools extension installed you can find a next-router store.

    • @kishanthshanthakumar7637
      @kishanthshanthakumar7637 Год назад +1

      hi , if i remove "use client" in page.tsx i receive issue "Error : (0 , _react.createContext) is not a function". i dont like to install third party "server only" . i just want to know , is it a best practice to use "use client" ?? any way to implement redux tool kit without using "use client" ??

    • @simbarashemaunga5575
      @simbarashemaunga5575 Год назад +2

      Bro, much appreciated, shouldn't you be like teaching us more of this stuff,

    • @yannikiforov3405
      @yannikiforov3405 Год назад +4

      For example, i have asyncThunk "fetchPosts" where i just fetch posts and i want my app to fetch posts on initilization , in CSR we usually just dispatch action by hand in app.js file since we have access to the store. How can we implement this logic in Next with App Router Approach?

    • @АртёмСенькевич-ы5с
      @АртёмСенькевич-ы5с Год назад

      ​@@yannikiforov3405выносишь функцию сервера в отдельную папку и делаешь там файл, где будут храниться твои функции и делаешь сверху "use server" и всё твоя функция будет выполняться на сервере, функцию Redux ты можешь просто экспортировать в твой файл страницы и там сделать "use client"

    • @yannikiforov3405
      @yannikiforov3405 Год назад +1

      @@rhinoman86 In case your application parent component is client side then you can use async thunk from redux (remember redux working only on client, it doesn't work on server), if it's server component then you can use built-in upgraded fetch method from Next as one of the options. Depends on how exactly you design the application. I just think if you about to wrap whole app in redux provider (meaning make it render on fully client side) then maybe you no need Next at all but you can still build Next app using only client components and using next features. This is my thoughts

  • @jaimepuentecontreras7347
    @jaimepuentecontreras7347 Год назад +2

    I love your english, I am a spanish speaker and I can understand any single word you say, that's wonderful. Nice tutorial

  • @sylvesterasiedu
    @sylvesterasiedu Год назад +2

    Thanks for explaining this clearly. Most other RUclipsrs tend to assume this knowledge is common so move along without such detail as you have provided. Thanks

  • @iangreene6519
    @iangreene6519 Год назад +2

    this is the only resource i have found on the subject that explains it well enough to implement my own logic.

  • @umeshkumarbedi7216
    @umeshkumarbedi7216 10 месяцев назад +2

    Thanks a lot. It's really helpful. You completed the major thing only in 13 minutes. Good knowledge.

  • @Aditya_sharma09
    @Aditya_sharma09 Год назад +2

    I was upset for 24 hours. Everything felt easy after watching one of your videos...thankuu so much.. 🇮🇳

  • @Theokondak
    @Theokondak Год назад +12

    Imo, worst thing with Next13 is that it's a framework that tries to lock you in the Vercel ecosystem.

  • @CodeElectrofying
    @CodeElectrofying 3 месяца назад

    Really Bro thanks a lot for explaining this so clearly. This helped me to build the app which i was not able to because of this redux error thanks a lot bro for this help keep making this sort of videos with simplicity and clarity

  • @maruf-procode
    @maruf-procode Год назад +5

    It works but if I refresh page it shows following error, Unhandled Runtime Error
    Error: could not find react-redux context value; please ensure the component is wrapped in a

  • @adamtrieseverything
    @adamtrieseverything Год назад +10

    I can't thank you enough for this - it helped me so much

    • @NativeNotify
      @NativeNotify  Год назад +1

      I'm glad it was so helpful! I was completely lost at first with the new app directory system. I hoped this video would be helpful for others

  • @tech3425
    @tech3425 Год назад +10

    Does wrapping the children with the component make every single child component a client side component?
    If that's the case, doesn't it destroy the whole point of the app directory?

    • @NativeNotify
      @NativeNotify  Год назад +10

      No it doesn't. You still have to say 'use client'; on the child components that you want to access the Redux store. They're still server side by default.

    • @tech3425
      @tech3425 Год назад +1

      @@NativeNotify Cool!

    • @BobbyW0nder
      @BobbyW0nder Год назад +2

      @@NativeNotify Very cool!

    • @felipesalazar4000
      @felipesalazar4000 Год назад +3

      @@NativeNotify are you sure? Because for what I search all the children of a client-side component/provider will be a client-side component...

    • @felipesalazar4000
      @felipesalazar4000 Год назад +4

      @@NativeNotify I think the best approach is only wrapping the on those components that will need to be a client-side

  • @bislan-aranyan
    @bislan-aranyan Год назад +1

    oh my, thank you so much. I searched this ptoblem 4 hours

  • @shamstabraizbaig938
    @shamstabraizbaig938 Год назад +2

    I am experiencing an issue where I am unable to make progress due to an error. Here is the error message:
    "Unhandled Runtime Error
    Error: Could not find the react-redux context value. Please make sure that the component is wrapped in a ."

  • @gemanepa5455
    @gemanepa5455 Год назад +1

    What if I want to store data coming from the server in the initial state of the redux store?

  • @satvikkushwaha9326
    @satvikkushwaha9326 7 месяцев назад +1

    thanks man , great tutorial , quite helpful

  • @zain.sadaqat
    @zain.sadaqat 6 месяцев назад

    Wrapping clinet-side {children} in the layout.tsx file, isn't convert the whole app into client side?

  • @pradhyumnsharma976
    @pradhyumnsharma976 Год назад

    Thanks a lot. Stucked at error, solved by your video

  • @aynuayex
    @aynuayex 10 месяцев назад

    sorry, i do not get, you are creating GlobalRedux with in the app folder, does not it be part of the route and cause in inefficiency in my app, please correct me if i am wrong.

  • @namelesssnerd
    @namelesssnerd Год назад +1

    very informative ❤❤❤❤💻💻

  • @redeagledave
    @redeagledave Год назад +1

    Thank you very much for this great tutorial, this helped me so much! 🥰

  • @salihuumar3138
    @salihuumar3138 Год назад +1

    Straight forward and simple

  • @moeinpourhamzeh1508
    @moeinpourhamzeh1508 11 месяцев назад

    This tutorial was awesome. Can you make another video on how to call backend from slices?

  • @paydrostylin7167
    @paydrostylin7167 Год назад +3

    Very very informative and much needed. I am studying Next13 right now to master it and your info is helping my comprehension on these features and how to use them properly. 🙌 Thought I would pay you back with some engagement and like/ share 😅💯

  • @xDTAT0XIC
    @xDTAT0XIC Год назад +1

    I keep getting an issue when I run the build script. Does anyone else have this issue? I get this error: Error occurred prerendering page "/".

    • @MauroMercuri
      @MauroMercuri Год назад

      I've encountered the same problem and I didn't find any solution..

  • @zergzerg4844
    @zergzerg4844 2 месяца назад

    What's a point of this? If you need SEO your settings is not gonna be work, but if you don't you just could use react+toolkit. The main reason people use nextjs is SSR, for seo, so do you know how to make ssr and toolkit work together?

  • @romanus_y
    @romanus_y Год назад

    Is it good to use "use client" in every page.tsx? Otherwise, it is difficult to work with redux and context. I once heard that this is bad practice, and page.tsx should be left to the server. Where is the truth?)

  • @asad_heidari
    @asad_heidari Год назад +1

    thank for this toturial, it is help me so much

  • @azeezabass288
    @azeezabass288 2 месяца назад

    Doesn't that make all the segments the client side??

  • @SpriteTheDude
    @SpriteTheDude Год назад +1

    ok but now any component that uses states from redux will be client side, right?

    • @NativeNotify
      @NativeNotify  Год назад +1

      Yes that is correct. They have to be client side to use Redux since Redux lives on the client side

  • @terrymarr5265
    @terrymarr5265 Год назад +1

    I searched for hours to try to get this to work. The only problem is that I'm not using typescript. I'm not sure how to set up the store without it. Do you have a plain js version?

    • @davidmomoh7019
      @davidmomoh7019 Год назад

      I think if you ignore adding the typings, js would figure exactly what you're trying to do. But if it doesn't work, you can ask ChatGPT.

  • @BirTutamTemeki
    @BirTutamTemeki Год назад

    It's was very short and helpful video

  • @prasenjit1110
    @prasenjit1110 5 месяцев назад

    Thanks, Its too good... need to change file extension .js to tsx

  • @AymanAli-lt3ro
    @AymanAli-lt3ro 10 месяцев назад

    What happens when you move from one page to the other. will the store still be available?

    • @NativeNotify
      @NativeNotify  10 месяцев назад

      Yes it will if you set it up the way it's set up in the video

  • @АбайКарагулов
    @АбайКарагулов Год назад +1

    Hello, how can we use redux on server side rendering ?

    • @bjornallvin3162
      @bjornallvin3162 Год назад +1

      Check this video out for how to use redux on both server and client component: ruclips.net/video/dRLjoT4r-jc/видео.html&ab_channel=JackHerrington

    • @praiseoshilim1006
      @praiseoshilim1006 10 месяцев назад +1

      please the video link is private, could you share a public video ? I mean the video showing how to use redux in server components@@bjornallvin3162

  • @adebayoraheem5183
    @adebayoraheem5183 Год назад +2

    This is a very great tutorial, I’ve been searching for something like this for a while now. Thanks 🙏🏽
    I have a question though, can redux persist work with this? If yes, how?

  • @PinkPanther6
    @PinkPanther6 Год назад +1

    Thank you so much. Also make videos on how to integrate API in nextjs 13.

    • @NativeNotify
      @NativeNotify  Год назад

      This video talks about APIs in nextjs 13: ruclips.net/video/yRJd_tlHu9I/видео.html

  • @ulugbek_temirov
    @ulugbek_temirov Год назад

    Thanks man! That helped me.

  • @seananih7609
    @seananih7609 Год назад +1

    Thank you man, great and concice video!

  • @javascript-shorts
    @javascript-shorts Год назад

    Does state persist when you navigate to diferent page?

    • @NativeNotify
      @NativeNotify  Год назад

      Yes it does

    • @javascript-shorts
      @javascript-shorts Год назад

      @@NativeNotify i followed your tutorial and state is persist in dev mode but when deploy to netlify it is not.

    • @javascript-shorts
      @javascript-shorts Год назад

      I have deployed the same code to vercel and state persists. So i look like vercel and netlify publish codebase in diferent way. Can anyone explain that?

  • @emanuelzarazaga3581
    @emanuelzarazaga3581 Год назад

    Excellent video, thank you very much. Has anyone used createWrapper from the library next-redux-wrapper?

  • @lefthandOK
    @lefthandOK 8 месяцев назад

    Thank you! It's work

  • @raulparra4678
    @raulparra4678 Год назад +1

    Thanks. You help me so much.

  • @mydaily21
    @mydaily21 Год назад

    on me, why props {children}
    must be given a type children: React.ReactNode; ?

  • @farouktouil5036
    @farouktouil5036 Год назад +3

    It works!💯

  • @jamesalphonse1099
    @jamesalphonse1099 9 месяцев назад +1

    For anyone watching this, it seems you only need 'use client' in the Providers.tsx component, not in every redux file.

  • @kamichikora6035
    @kamichikora6035 Год назад +1

    Dude, you saved my life

  • @A7MDMahmoud
    @A7MDMahmoud Месяц назад +1

    thank you bro

  • @frankylopez4477
    @frankylopez4477 Год назад +1

    Thanks!

  • @sdsim1
    @sdsim1 6 месяцев назад

    Great 👍🎊

  • @Sergei546
    @Sergei546 Год назад

    the best video!! thk

  • @KurooNegai
    @KurooNegai 5 месяцев назад +1

    Why all software youtubers obsessed with "counter"!?

  • @Proviper666
    @Proviper666 3 месяца назад

    I searched for CRUD and Redux and NextJS. ;(

  • @NoFun-1672
    @NoFun-1672 Год назад

    Very Nice

  • @dyay108
    @dyay108 Год назад

    my savior

  • @waliahmed3035
    @waliahmed3035 Год назад +3

    You have messed up the whole concept of SSR with this lol

  • @ทําดีหลากหลาย

    nice bro

  • @Demonata1223
    @Demonata1223 Год назад

    Youre just side stepping SSR completely and turning everything into client components. Thats not super helpful. Why not touch on preloading/hydrating the state from the server

  • @soulking6982
    @soulking6982 Год назад

    Thanks bro

  • @EricTsai-rj9vm
    @EricTsai-rj9vm Год назад

    thanks s lot

  • @lokeshstufs
    @lokeshstufs Год назад

    Pls create the Rant video on this. Am a bit disappointed with it too. Not supporting hooks & store in server components is bad. Practically all components would be interactive with states. My Next app would be full of CSR components, I would instead prefer going back to React.

  • @shantanusharma4901
    @shantanusharma4901 Год назад

    You are God 🙏

    • @NativeNotify
      @NativeNotify  Год назад +1

      There's only one God, the Father. And Jesus Christ is His only begotten Son. I'm nothing without Jesus

  • @TarasovFrontDev
    @TarasovFrontDev Год назад

    First five minutes is just imports libraries. What a waste of my time.

  • @nwdev4258
    @nwdev4258 Год назад +1

    i have error undefined" is not valid JSON at JSON.parse () at parseModel

    • @weejohntee
      @weejohntee Год назад

      I get this too when i say 'use client' in layout.js, no idea how to fix it :(

    • @weejohntee
      @weejohntee Год назад

      Downgraded Next from 13.3 to 13.2.4 works theres a bug in Windows backslash something something