Next.js Best Practices in 2024
Answered
Grass carp posted this in #help-forum
Grass carpOP
Hello everyone, I am a front-end developer and a next.js beginner. Here are some libraries I have been learning recently about react and next.js, but I found that the React ecosystem is too rich. I don’t know which are the best practices for next.js in 2024. Do I have to learn all of them, or which libraries are more popular?
1. Prisma, drizzle or typeorm?
2. React query or swr, or nothing?
3. Is trpc necessary?
4. What is the state management solution? I just used zustand recently
5. Is react-hook-form necessary, or should I use native action
6. Do I need a permission solution? What about auth.js?
1. Prisma, drizzle or typeorm?
2. React query or swr, or nothing?
3. Is trpc necessary?
4. What is the state management solution? I just used zustand recently
5. Is react-hook-form necessary, or should I use native action
6. Do I need a permission solution? What about auth.js?
Answered by Lukas
1. Drizzle seems to be trending at the moment.
2. If you're using app directory, likely nothing. Grab react query if you end up doing lots of client fetching.
3. Same as above. Do you need the end-to-end type safety? If you're fetching data on the server with a orm, you might not. You can always add it later if you have an api that you need types for. If all you're doing is just fetching from the db serverside and using server actions, you probably don't need it.
4. Zustand is great, jotai (made by the same person) is great too (and considered simpler). Take a look at both and see what you need for your project.
5. Use server actions. With useFormStatus and useFormState, you can basically do everything (besides multi-page forms.)
2. If you're using app directory, likely nothing. Grab react query if you end up doing lots of client fetching.
3. Same as above. Do you need the end-to-end type safety? If you're fetching data on the server with a orm, you might not. You can always add it later if you have an api that you need types for. If all you're doing is just fetching from the db serverside and using server actions, you probably don't need it.
4. Zustand is great, jotai (made by the same person) is great too (and considered simpler). Take a look at both and see what you need for your project.
5. Use server actions. With useFormStatus and useFormState, you can basically do everything (besides multi-page forms.)
6 Replies
1. Drizzle seems to be trending at the moment.
2. If you're using app directory, likely nothing. Grab react query if you end up doing lots of client fetching.
3. Same as above. Do you need the end-to-end type safety? If you're fetching data on the server with a orm, you might not. You can always add it later if you have an api that you need types for. If all you're doing is just fetching from the db serverside and using server actions, you probably don't need it.
4. Zustand is great, jotai (made by the same person) is great too (and considered simpler). Take a look at both and see what you need for your project.
5. Use server actions. With useFormStatus and useFormState, you can basically do everything (besides multi-page forms.)
2. If you're using app directory, likely nothing. Grab react query if you end up doing lots of client fetching.
3. Same as above. Do you need the end-to-end type safety? If you're fetching data on the server with a orm, you might not. You can always add it later if you have an api that you need types for. If all you're doing is just fetching from the db serverside and using server actions, you probably don't need it.
4. Zustand is great, jotai (made by the same person) is great too (and considered simpler). Take a look at both and see what you need for your project.
5. Use server actions. With useFormStatus and useFormState, you can basically do everything (besides multi-page forms.)
Answer
6. next auth is generally the way to go. if you like wasting money and being lazy, you can also use clerk. If you're using something like supabase, their built-in primitives work great too. Just don't try to build your own system from scratch.
I can speak just about myself and would answer you:
Prisma, drizzle or typeorm?Drizzle
React query or swr, or nothing?React Query
Is trpc necessary?No
What is the state management solution? I just used zustand recentlyReact states are best
Is react-hook-form necessary, or should I use native actionNo, use normal state management and use the KISS principle
Do I need a permission solution? What about auth.js?Depends on your app. If needed yes, else no. NextAuth > auth.js
Grass carpOP
I really appreciate your answer.
I really appreciate your answer.
please mark solution