1

All YouTube videos I found and the official docs show how to use Redux for a very specific task, like a todo list app. The example mostly have only one type of data (e.g. todo tasks).

Unfortunately, i have not found a guide how to deal with the following problem:

I have a dashboard app, which displays many different types of data (over 20; contacts data, customer data, invoice data, file information etc.). I have started using Redux like shown in the docs.

I created actions for each type of data. For example:

FETCH_CONTACTS
CREATE_CONTACT
DELETE CONTACT

FETCH_INVOICES
...

My question is, how do I handle my data? Because of the fact, that I have over 20 types of data, invoices should only be loaded, if the user opens /invoices, contacts only if he opens /contacts etc. Also what is the best why to implement a filter (search), which gets handled by the server, since a single data type can have over 1000 entries.

Moreover, how do I manage authentication in Redux? Should I have auth actions like:

TRY_LOGIN
LOGOUT
...
Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Ruudy
  • 217
  • 1
  • 4
  • 17
  • This is the thing with Redux and these kind of stores, they let you do anything you want. You can start by asking yourself: [Should everything be in redux?](https://stackoverflow.com/q/35328056/1218980) – Emile Bergeron Apr 23 '19 at 16:50
  • There's also a FAQ entry about [organizing your Redux store's state](https://redux.js.org/faq/organizing-state). – Emile Bergeron Apr 23 '19 at 16:53
  • 1
    My personal rule of thumb is: Anything that relates to business logic should be kept in the store, with actions handling the logic. Anything related to UI/UX is in the components state, except some specific global state of your UI that is shared across the app. – Emile Bergeron Apr 23 '19 at 16:55
  • @EmileBergeron Yes, I have already decided, that only business logic should be handled by Redux. My question is more about how to use Redux (or with middlewares) to only load the data i need. And how to handle authentication. – Ruudy Apr 23 '19 at 16:58
  • Unfortunately, it's kind of 2 questions that are way too broad and opinion-based for Stack overflow. – Emile Bergeron Apr 23 '19 at 17:01
  • You can have 20 separate reducers for each type of data. And keep a common structure for all of the reducers. Like `{arr:[], obj:{}, stats:{}}`. and create actions like `updateArr`, `updateObj` & `updateStats`. Finlay, you can keep this structure for all of the reducers to make the process easier. – Prabu samvel Apr 23 '19 at 17:04
  • @EmileBergeron Do you know any resources which cover this topics? Any open-source project I could take as an example? – Ruudy Apr 23 '19 at 17:04
  • Have you seen this example? https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/todos – kenodek Apr 23 '19 at 17:06
  • 2
    Asking for examples and/or off-site resources is also off-topic for Stack overflow. Authentication and data management is much more than just Redux and can span across a huge part of an app, so it boils down to _"how to manage authentication in a frontend app"_. Once you've found a way for your use-case you're happy with, mixing Redux in becomes trivial. – Emile Bergeron Apr 23 '19 at 17:10
  • @DominikTargosz I literally wrote that I mostly saw examples with todo lists. My question is how do I use Redux if I have not only one class of data (todo tasks), but multiple. – Ruudy Apr 23 '19 at 17:11
  • Even with the todo list example, there's a thousand way you could manage the data, depending on your use-case, constraints and preferences. – Emile Bergeron Apr 23 '19 at 17:15
  • @EmileBergeron Well you started posting off-site resources, so I thought it was ok. Also, thank you for your comments, but saying the question is too complex to ask does not really help. – Ruudy Apr 23 '19 at 17:18
  • I tried to share the rules while still pointing you in the right direction, but you won't get official answers here. I'm pushing the limit on what comments are for. – Emile Bergeron Apr 23 '19 at 17:20

0 Answers0