Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React + Redux with a rest api?

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.

like image 764
Dave Avatar asked Feb 10 '16 11:02

Dave


People also ask

Is Redux deprecated?

The redux core package still works, but today we consider it to be obsolete.

Can I use Redux and context API?

If you're only using Redux to avoid passing down props, you can replace it with Context API. Context is great for sharing trivial pieces of state between components. Redux is much more powerful and provides a set of handy features that Context doesn't have.


1 Answers

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.

like image 72
Victor Suzdalev Avatar answered Oct 13 '22 00:10

Victor Suzdalev