I have a simple CRUD app I am building in node, and have finished creating the rest API in Express. I am now looking to add front end functionality and wish to use react + redux as a learning exercise. It seems however all of the tutorials around this access the data directly using Redux, rather than interfacing with an internal API.
My question is, is that the correct way to build a SPA with redux? I was under the impression it was best to separate the front end from the backend so that I could, for example, build an iPhone app and not have to rebuild the backend.
Thanks in advance.
Redux itself has nothing to do with API communication, it's the library for client-side state management. You can use whatever approach for firing and handling requests, most common are using custom api-connecting middleware, returning functions, which fire requests, from action-creators and using them with thunk-middleware or using alternative approaches like rx-bridges or sagas.
Start with: https://egghead.io/series/getting-started-with-redux
Reffer to: What is best practice to communicate between React components and services?
Redux by design forces to build SPA application.
First, see examples from redux docs, "Real World" is most useful:
https://github.com/reactjs/redux/tree/master/examples/real-world
Then, you can research useful utils like redux-promise-middleware.
Finally, you can try to use some complex utils for connect your redux-app with API. redux-rest-adapter is one of them.
Related
I am a hobby programmer with some experience in React, primarily using Firebase for my backend. Recently, I have started using Next.js and am wondering if I can use it as a small JSON-based database for local applications on my Raspberry Pi. I have set up LowDB and can access it from server-side rendered components, but I am unsure of the best way to make them accessible from interactive frontend components, such as allowing user input and saving it to the database. I have considered using Next.js's own API endpoint, but I am unsure if this is the most efficient and desired method. It feels strange to use a DB query in server-side components but an API for data changes.
NextJs as great framework derived from React, its more for UI frontend, for interacting with DB normally you would use an NodeJS API framework like NestJs or simply Express with some kickstart templates.
You will not like use SSC since its just not the way/goal it was designed. like dentist doctor doing eye check haha
Happy coding!
I am planning out my first project using a Headless CMS. I have settled on using Strapi for my project. Is it logical to use Strapi while not using SPA framework/library? I want to use express and EJS to build my website and Strapi as the backend. Is this okay to do? I assume you would use this with your node server that will make REST requests to the Strapi API. Am I glossing over anything?
It's definitely logical. Just make sure to create your own API-endpoints within Strapi and secure the data as much as possible. So try to do most logic within Node.js and not within front-end.
As far as I am concerned this is pointless to make a headless CMS like strapi, without using a library/framework. There is so many reason why this is no sense. Above of all, in react you can use reusable components, writing in jsx etc. This is something that vanilla javascript no have.
Learn how to make first blog in react and connect it to strapi would you take about 10h if you know basic of javascript, css and html. This my opinion.
I'm creating a web app and I'm wondering if it's possible to create it using both REST and GraphQl. I don't mean I wan't to wrap REST in graphql. It is a web app with a variety of functionalities and graphql would be best suited towards the blog portion of the app but we've already constructed the rest of it using REST. Would it be possible/bad practice to use them for the respective parts of the app?
I don't see any problem with that. Just make sure to create a single API abstraction that would internally handle both cases so that the app itself is not concerned about that (in case you'll want to go all-in with GraphQL at some point).
As we're building a Meteor React web application which will be presented inside a web view inside a react native application. As you can probably tell by reading that sentence, this doesn't make much sense, but due to time constraints and the fact that the react native application is made by another team, we have decided to present it in a web view for now, and eventually convert it to RN as well.
So to prevent having to write everything twice, is there a way to use React Native components in Meteor? (So use <View> for example instead of <div>).
If you want to go down this path, you can use react-native-web to build React Native components for the web.
Just want to warn that while building your web client with RN components will definitely help you transition, you will still pretty much have to scrap all your client side Meteor logic when you transition later. The best RN meteor client currently is react-native-meteor and is more of a proof of concept than anything -- trying to emulate key features of Meteor with a wrapper using a DDP client, but definitely not there yet.
So in the end, you're going to put in some serious hours making the conversion later or scrapping Meteor altogether when you go full native. If you're a fan of Meteor, I would suggest trying apollo made by the folks at Meteor and works out of the box with RN. You can still get all the best features of Meteor like reactive data, optimistic UI, subscriptions, etc. and the learning curve is pretty mild.
I started learning React and It's really amazing, I enjoy coding with React.
In official doc said that React can be used for UI only.
React is a JavaScript library for creating user interfaces by Facebook
and Instagram. Many people choose to think of React as the V in MVC.
So, Can I use React with Angular.js for UI? Is that a good idea or bad? (why?)
Googling, I found lib called ngReact. It allows use React Components in Angular.
What you think about this? Give me an idea.
Thanks in advance.
I have been using ngReact for an application which is written on angular.
We had to switch the view for some parts of the applications to react because of the constant data changes and is expensive for digest cycles.
angularjs is good to handle the ui for most applications unless you are looking at rendering a lot of data. Even in that case if the data is not changing you can use single binding of angular. If you have data that is constantly changing your view might get slow in angular that is the only downside with existing angular versions.
That being said using ngReact can become tricky at times. Mainly communicating with angular services, basic directives like ui-sref and react nested components.
Be sure of the reason for using ngReact.
using react, angular and even a combination should be more than a personal preference.
Ive recently my self started to learn React. And you are completly right React is just for UI and dosent support any Model / Controlers.
But mixing React & Angular for me seems a bit odd? Angular got its own template engine with their directvies (Angular 1.xx). So it would be a bit akward to match these too frame works.
If i was you i would look into this thing called Redux, witch is another way of doing flux architecture. This is also the architecture that React is initially thought upon. And its really powerful.
Here is a couple of nice to have to get into:
https://egghead.io/series/getting-started-with-redux - This is a free course on Redux (witch you want to use with storing data for you react views)
You can actually interoperate Angular and React really nicely with https://github.com/bcherny/ngimport. My team and I have used it successfully on our 10k file hybrid Angular+React project - let me know if I can answer any questions!