2

I come from RoR world, and would like to change my application using Redux and React.

React is very simple to understand, you build it up and connect to Redux using web-sockets (Why not just xhr?), Redux accept different actions and respond to React etc.

What I don't understand is, do you save all users in redux store? Or do you use another noSQL to save them? And when I terminate the redux store and start it up again, does my data vanish? I can't find article describing this?

Dmitry Shvedov
  • 3,169
  • 4
  • 39
  • 51
Jamal James
  • 91
  • 2
  • 9
  • Redux is some kind of global state and not meant to store persistent data. – Lars Graubner Mar 04 '16 at 11:54
  • Redux only manages state on the client side (in the browser). It is not a database. – Davin Tryon Mar 04 '16 at 12:01
  • so do I getState(); save it to disk and load it in the store everytime the server restart? – Jamal James Mar 04 '16 at 12:23
  • 1
    @JamalJames, yes if you want persistent data you must store it in a database, or localStorage, then read from that each time the app loads and store it in Redux. – speak Mar 04 '16 at 12:38
  • @speak so why not just use Hapijs instead of redux? is it because the View will get messy with too many api calls? – Jamal James Mar 04 '16 at 12:42
  • @JamalJames I have no experience with Hapijs, but they do not seem to be achieving the same thing, from a quick glance people use Hapijs and Redux to complement one another, not replace. – speak Mar 04 '16 at 12:48

1 Answers1

3

Redux manages state of the client side. Example of what redux handles:

  • filter in table changed (set state to "loading" and replace table with spinner)
  • results were loaded (display results in the table)
  • loading of results failed (show error message)

It does not handle remote communication in itself. I assume that you got the impression that you needs websockets from this tutorial. What happens there is that redux is used on server as well as on client. And websockets are used to make the communication between server and client realtime. The same actions that are executed locally are executed on server and that allows you to propagate them to other clients.

More about AJAX calls and handling asynchronousness in redux:

Community
  • 1
  • 1
Tomáš Fejfar
  • 11,129
  • 8
  • 54
  • 82