Using NextJS and Rails API
Unanswered
Cape lion posted this in #help-forum
Cape lionOP
Is anyone here using NextJS application that calls to a rails api for its server data?
5 Replies
Dwarf Crocodile
Next.JS is a "fullstack" framework so it is recommended to do backend and frontend both in nextjs. However i've done something similar to what your suggesting but with a Next.JS and Laravel stack instead and it works like you'd expect and I even have it running on some personal projects that work great.
That being said your missing out on alot of next-js features like server components by fetching the data as you'd be introducing latency to your server running rails. That's why even though it works you'd be much better off doing data fetching and stuff inside of server components, entirely mitigating the data fetching entirely to your rails server.
## If you really want to use rails
then it would be much better to use just react inside your rails application. I know nothing of rails but it seems like this blog post explains it well.
https://blog.logrocket.com/how-to-use-react-ruby-on-rails/
That being said your missing out on alot of next-js features like server components by fetching the data as you'd be introducing latency to your server running rails. That's why even though it works you'd be much better off doing data fetching and stuff inside of server components, entirely mitigating the data fetching entirely to your rails server.
## If you really want to use rails
then it would be much better to use just react inside your rails application. I know nothing of rails but it seems like this blog post explains it well.
https://blog.logrocket.com/how-to-use-react-ruby-on-rails/
Cape lionOP
Thanks so much @Dwarf Crocodile .
Dwarf Crocodile
np
@Dwarf Crocodile Next.JS is a "fullstack" framework so it is recommended to do backend and frontend both in nextjs. However i've done something similar to what your suggesting but with a Next.JS and Laravel stack instead and it works like you'd expect and I even have it running on some personal projects that work great.
That being said your missing out on alot of next-js features like server components by fetching the data as you'd be introducing latency to your server running rails. That's why even though it works you'd be much better off doing data fetching and stuff inside of server components, entirely mitigating the data fetching entirely to your rails server.
## If you really want to use rails
then it would be much better to use just react inside your rails application. I know nothing of rails but it seems like this blog post explains it well.
https://blog.logrocket.com/how-to-use-react-ruby-on-rails/
Cape lionOP
I agree that I'll be missing out. However, there are no current plans to rewrite the backend in Next.JS but to keep the rails api for now.
Cuban Crocodile
I have experience.