V
V
Vasaho2021-12-27 22:15:45
React
Vasaho, 2021-12-27 22:15:45

What options for state management are the most correct?

I would like to know from more experienced people what options are most correct for these tasks:
1.
There is an application on React + Redux, the essence is simple, there is a main one, which shows a list of books. All these books are stored in the editorial state when the application is loaded. Books have 3 buttons - read, in progress and favorite. (true/false) When you click on one of these buttons, a banal state update occurs, something like this:

case ActionType.UPDATE_BOOK_FLAGS:
      return {
        ...state,
        books: state.books.map((book) =>
          book.id === action.bookId
            ? { ...book, flags: action.payload }
            : book,
        )
      };

You can also click on the book and go to its separate page, where there are also these 3 buttons.
So the question is, how best to manage the state of the flags of a separate page of the book - through redax or just make a local state of these flags and send a POST request with an updated flag on click?

2.
The page of the book from point 1 has a list of comments and a form for submitting them, is it better to store the state of comments and forms locally in the component or use redux?
Also, after adding/deleting/editing a comment, would it be best to immediately make a GET request to get an up-to-date list of comments from the server?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question