React Forms with Redux & RTK Query | MERN Stack Tutorial

Поділитися
Вставка
  • Опубліковано 25 гру 2024

КОМЕНТАРІ •

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  2 роки тому +4

    Part 7 of The MERN Stack Project Series - This video shows how to build React form components to complete CRUD operations in our MERN Stack Project. We are using Redux and RTK Query so this video also shows how these CRUD operations are state mutations for Redux. This tutorial is not for beginners. If you are a beginner, check out my full courses all in one playlist here: ua-cam.com/play/PL0Zuz27SZ-6M1Uopt6_VL3gf3cpMnwavm.html

    • @MrPindro
      @MrPindro Рік тому

      The createNewNote controller doesn’t work!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому

      @@MrPindro Yes it does. The only issue since this tutorial was published nearly a year ago is that the Mongoose sequence package does not work with the latest version of Mongoose. This has been discussed in these comments and in my discord forum. You can roll back to the version of Mongoose that I list in my package.json in the course resources, or you can find an equivalent dependency to Mongoose sequence. Some are listed in both the comments and in my discord.

    • @MrPindro
      @MrPindro Рік тому

      Oh!! I get it now. Practically everything else works aside from creating a new note.
      Anyway, i appreciate your response! 🤝

    • @MrPindro
      @MrPindro Рік тому

      Hey Dave, i can’t seem to find a link to the discord convo you previously mentioned. Mind copy pasting for me? The link that is. Thanks in advance!

    • @MrPindro
      @MrPindro Рік тому

      Btw, i just fixed it by having the mongoose-sequence definition on the Note.js in the models folder completely wiped. 😅 thanks again good lad! 🤝

  • @ahmad-murery
    @ahmad-murery 2 роки тому

    Hello Dave,
    I haven't bother you in a while, so here I am again 😎
    at 19:44 we used the ROLES key for the option text, and that's ok since both keys and values are identical,
    but just in case we want to localize this app I think we can use ROLES[role]
    Thanks for your continued efforts to make things easier for us

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      Hello Ahmad! Good to hear from you my friend. I hope all is well for you. 🙏💯

    • @ahmad-murery
      @ahmad-murery 2 роки тому

      @@DaveGrayTeachesCode We have survived so far 😐,
      Thank for asking my friend 🤍

  • @Pareshbpatel
    @Pareshbpatel Рік тому

    I experimented with react-query before I took this tutorial. I will be using RTK Query from now on. Thanks to you, Dave. You have explained the use of RTK Query very well. Thanks again.
    {2023-02-28}, {2023-03-01}

  • @teetanrobotics5363
    @teetanrobotics5363 2 роки тому +2

    God level programmer and teacher🤩. Love your content !!

  • @sailee5208
    @sailee5208 2 роки тому +1

    Thank you Dave! All up to date and looking forward to continuing the project in the next video.

  • @annusingh4694
    @annusingh4694 2 роки тому +6

    This course is gold 💯 Beautifully structured and detailed.

  • @cuentamovil456
    @cuentamovil456 2 роки тому +1

    I've finally understood RTK Query thanks to this video and to your Redux-Toolkit playlist. Thank you very very much for your great work!! I hope you reach 500k subs or more before the year ends!!🥳🥳🥳

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      You are welcome! Looking like I may hit 100k by year end and I'll be happy with that.. but I'll keep going! 💯🚀

  • @codernerd7076
    @codernerd7076 2 роки тому

    This series keep getting better, please keep going!

  • @adarshalone7579
    @adarshalone7579 2 роки тому +2

    Sir you explain every single details about MERN stack. And i love the way you explain.... Love from fellow coders..

  • @vladimirjovanovic3540
    @vladimirjovanovic3540 10 місяців тому

    You are excellent teacher!!!!

  • @Sylar7773
    @Sylar7773 2 роки тому

    YOU are the BEST teacher, thank YOU so much!!!

  • @TechWithSally4D
    @TechWithSally4D 2 роки тому

    Awesome Buddy! Really Love Your Tutorial, Made as Simple as Possible

  • @DASDOS
    @DASDOS 2 роки тому +1

    I love your courses

  • @uzomanwanne2751
    @uzomanwanne2751 Рік тому

    Thanks so much for this course Dave.

  • @fa1con989
    @fa1con989 2 роки тому

    I really enjoyed this course 😇
    I just have a small request if possible please make a tutorial on microservices and the CI/CD pipeline.

  • @kevinalfaro4820
    @kevinalfaro4820 2 роки тому

    Hey Dave, loving the content. Any plans on releasing a NEXT Js series? There’s a lot of talk about the T3 stack which utilizes Next, Prisma for database, and tRPC over React Query.
    Would absolutely love if you could try to do that, you are one of the best teachers on here by far!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      Yes, I do have plans for a NextJS series - and thanks for the detailed request and kind words! 🙏💯🚀

    • @kevinalfaro4820
      @kevinalfaro4820 2 роки тому

      @@DaveGrayTeachesCode thanks for getting back to me, any idea on when that can be expected Dave?

  • @marquessmalley1778
    @marquessmalley1778 Рік тому

    For some reason at 43:19, after implementing the prefetch component, the data stays on the edit form(which is expected) but after submitting the edited user and going back to the usersList, the edited user doesn't update until I refresh the page again. This was working previously but now I cant figure out what seems to be the problem here??

    • @sands570
      @sands570 Рік тому

      Hello, same here... Did you find out ?

  • @sonamohialdin3376
    @sonamohialdin3376 2 роки тому

    Amazing tutorial thank you very much

  • @mariusguissou4282
    @mariusguissou4282 2 роки тому

    very very good tutorial thanks :)👍👍👍👍❤❤❤

  • @gitterk
    @gitterk 2 місяці тому

    Another great tutorial DAVE! I've learned soooo much from your tutorials! I am running into an error at the end of lesson 6 though. I've triple checked and my code is identical to the repository. I get a cors error when my client is attempting to get the users from the server. I was able to solve this by bypassing the cors options and using app.use(cors()) instead in the server file, which I believe allows the client to fetch the data from any url. Could someone please help me understand what could be causing this? Thanks in advance!

  • @elAmigo805
    @elAmigo805 9 місяців тому

    Why do you sometimes destructure an imported hook with an array and sometimes as an object? How do you know when to use one or the other?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  9 місяців тому

      It depends on what you need the hook to return if you write a custom hook. If not a custom hook, the documentation tells you what the built-in hook returns.

  • @nicolascohen2465
    @nicolascohen2465 2 роки тому

    Hi Dave, I love your videos. I have a question... How can we implement a debounce strategy to an input of type text using RTK Query? I hope you answer, thanks anyway.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +5

      This would make a good tutorial for not only a useDebounce hook but also for a search input that automatically sends a request to the API when the input changes. Thank you for the request! 💯

    • @nicolascohen2465
      @nicolascohen2465 2 роки тому

      ​@@DaveGrayTeachesCode Coming Soon? I need to know hahaha. #anxiety

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      @@nicolascohen2465 sometime this year!

  • @abdulrahmanagboolaosho3582
    @abdulrahmanagboolaosho3582 2 роки тому

    Thanks for the awesome tutorial, I just have a quick question: Is there any reason for someone to want use useLazyGetNotesQuery or useLazyGetUsersQuery

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      The "lazy" versions provide "manual control over when the data fetching occurs". according to the docs. This means you would use them when you don't want to trigger the query when the component loads.

    • @abdulrahmanagboolaosho3582
      @abdulrahmanagboolaosho3582 2 роки тому

      @@DaveGrayTeachesCode thank you so much, you have helped me in ways you can’t imagine I am sincerely grateful to you

  • @zahidshaikh3122
    @zahidshaikh3122 2 роки тому

    Finally ♥️

  • @samiullahsheikh5015
    @samiullahsheikh5015 2 роки тому

    can you please explain the difference in keepUnusedData and polling?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      keepUnusedData = The amount of time in seconds that RTK Query will keep the data available AFTER no components are subscribed to the data. Components unsubscribe when they unmount.
      polling interval = The amount of time in seconds that RTK Query waits until it automatically sends another request for that query endpoint. This is important when others may be updating the data - like other employees in this example - and you need to see and work with the most recent data instead of stale data from the cache.

  • @chifou
    @chifou 2 роки тому

    Hello. Thanks for your videos. What is the better way to modify _id to id : in backend or frontend like you did?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      Either way works, but I prefer the frontend as shown. It is easy with the transformResponse example.

    • @chifou
      @chifou 2 роки тому

      @@DaveGrayTeachesCode thanks 👍🏻

  • @agalligani
    @agalligani Рік тому

    This is a follow-up to a comment on another thread where I ask about RTK & selectors created by getSelectors as done in the features slices. My problem is getting the selectors (or state, really) to "hydrate". I realize this can't happen unless the "get" builder query is invoked for the corresponding feature. But how do I force this to happen? For example if I have a feature called "Areas" and I want to us the "selectAllAreas" selector, I can force it to hydrate state by doing this: import { useGetAreasQuery, selectAllAreas } from "./areasApiSlice" and calling useGetAreasQuery first... By invoking useGetAreasQuery, state is hydrated & the selector "selectAllAreas" works. But from another content type, for example as you populate the User drop down in NewNotesForm using selectAllUsers, how does one "force" the state to hydrate? I must be missing something here. Is it in the course dialogue?

    • @agalligani
      @agalligani Рік тому

      Maybe this works in your course because the user has to log in first and you "persist" state? Is there a standard pattern to make this occur?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Рік тому +1

      I think you will find the full refactor to RTK Query that comes in a later chapter (video) helpful. The way to get new data - which is what I think you are wanting when you say "how does one force the state to hydrate" - is to invalidate an existing cache so another query takes place. You are correct that a user must be logged in with this app for much of anything to take place. The persist behavior is only for when a page is refreshed or a user navigates away and returns. Keep going with this project in full before trying to modify or build your own around it. I think RTK Query will be helpful for what you are trying to do.

    • @agalligani
      @agalligani Рік тому

      @@DaveGrayTeachesCode OK - I apologize. This is totally on me because I missed the Prefetch.js, skipped it in my application and reviewing the episode again this is what I am looking for. Thx

  • @nimp7582
    @nimp7582 2 роки тому

    In RTK, is every GET operations considered query and everything else is mutation?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      Not just in RTK, but overall, the other CRUD methods all mutate data. You query to Read - but everything else will change the cached data you have.

    • @nimp7582
      @nimp7582 2 роки тому

      @@DaveGrayTeachesCode That makes. Thank you so much for the tutorial btw. My only concern is that I dont feel confident about any of the API slices mutations/queries. The syntax and the various names are daunting. If I had to give a suggestion, it would be really nice if you explained more in depth where each of the variables were pulled from for stuff like provideTags, transformResponse, noteAdapter, etc.

  • @breldanmuthaka1120
    @breldanmuthaka1120 2 роки тому

    Sir, If we are subscribed to the endpoints in the Prefetch component. How come we still query the notes and users in the users and notes lists?
    Also if we invalidateTags on creating new users and posts, how come we still refresh the queries in the users list and notes list?
    I’m confused, but I guess that’s part of learning.😅

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +4

      Hi Breldan - Question 1) The prefetch component will only fetch once. Your data will become stale if you do not fetch any changes. 2) Good question - the reasoning is we want the data refreshed on all staff members web displays. Invalidating the cache does not automatically update the display of any logged in browser - it only impacts the cache (stored in the browser) of the user who made the update. Refreshing at a regular interval in the app will display new data for all workers viewing the notes or users lists.
      You're right! It is good that you ask questions - it is part of learning! 💯

  • @mahendranath2504
    @mahendranath2504 2 роки тому

    Thank you so much 🤗👍👏🙌👐🤝🙏

  • @somebody-17546
    @somebody-17546 2 роки тому

    Are there more videos in this course ?💖💖

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      I am building this course right now. New videos on Tuesdays and Fridays.

  • @domjag600
    @domjag600 Рік тому

    As of 2023 what are your thoughts on RTK Query vs ReactQuery?

  • @mrbilchalan
    @mrbilchalan 2 роки тому

    Hello Dave, my endpoint get multiple objects, means- {notesPerPage:12, notes:[...]} . I am still looking a way, how to handle notesPerPage. Should have do that by myself but I am not quick or great learner. If you hint something or tut some in your next lessons, it will be great. Thank you.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      It sounds like you are applying pagination. On the frontend, you can handle the notesPerPage value as you see in my pagination video: ua-cam.com/video/9ZbdwL5NSuQ/v-deo.html ...on the backend, if your frontend app sends the value for notesPerPage as part of the request body, you can destructure that value as you see other values have been received in the controller methods.

    • @mrbilchalan
      @mrbilchalan 2 роки тому

      @@DaveGrayTeachesCode I think my question is wrong.
      ----------------------------------------------------------------
      transformResponse: responseData => {
      const loadedNotes = responseData.map(note => {
      note.id = note._id
      return note
      });
      return notesAdapter.setAll(initialState, loadedNotes)
      },
      ----------------------------------------------------------------
      here loadedNotes store the notes array and set the initialState. but I have also other objects like notesPerPage and several others. If I set the initialState an array rather than object and destruct my desired objects from responseData and add to initialState along with notes array it doesn't work properly.
      I don't know if I express myself properly. Sometimes I feel angry why people talk in different languages.

  • @MrZiyak99
    @MrZiyak99 2 роки тому

    what is your opinion on storing form data in a redux slice

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      Great question! I only abstract state from the component when it is needed globally. If the state is only related to the specific form in the component, I usually keep it there.

  • @Kay-qg1vn
    @Kay-qg1vn 2 роки тому

    Hey Dave, are you familiar with htmx?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      It is interesting. I have not read much about it. I like my HTML to be as clean as possible, and this adds a bit more to it - but I do not know enough about it yet to form much of an opinion one way or the other.

    • @Kay-qg1vn
      @Kay-qg1vn 2 роки тому

      @@DaveGrayTeachesCode okay i understand, i thought maybe you are familiar with it, you are doing amazing by the way, your HTML and CSS courses are amazing!! Keep doing the amazing work. 👏

  • @rsrinivas6025
    @rsrinivas6025 2 роки тому

    Hii dave i have 6months of experience as react developer. I am requesting you to make one video. How one should understand the complex project (means code already written by some body) recently i moved one of the client location.they just assigning the tasks and they are not going to explain the thing properly. I basically want to know how to debug the project in various places and how to understand the api responses and flow of the project.please i am begging you to make a video on this no one in the youtube made one such video about it.and also my sincere request you to do one react project using complete Antd library video, no one explained Antd any where in the youtube.udey also has no as such course. I am waiting for you reply 😊😊😊 thank in advance

  • @Norfeldt
    @Norfeldt 2 роки тому +1

    You are a great teacher 🙌
    You might wanna checkout the new experimental feature in vscode called sticky headers. I found it useful myself. 🤗

  • @ronitafter2464
    @ronitafter2464 2 роки тому

    Great tutorial Dave, thank you! I was able to do everything, except adding notes in Postman(didnt know what to add in the JSON format). so unsurprisingly i 'm getting an error that localhost:3500/notes not found. Is there an example for the JSON format?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      Yes, I think you need to go back to lesson 4 in this series to see me do that very thing in a video.

    • @ronitafter2464
      @ronitafter2464 2 роки тому

      @@DaveGrayTeachesCode I'll do that, thanks!

  • @AhSoh7091
    @AhSoh7091 2 роки тому

    Hi Dave. Wish you can giving me some tips.
    I tried implement more with this to add some default state into userAdapter.getInitialState({ currentPage: 0}).
    How could I update the currentPage value state in getUsers GET method once the api return the value.

    • @AhSoh7091
      @AhSoh7091 2 роки тому

      I guess i more understanding it now after watched it again. usersApiSlice with adapter only handling the api and created the normalized state. if we want to mutation other state that should create another file like "authSlice" to handle the redux stuff and initialState. Thank you so much.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      Glad you got it!