The situation is as follows: 1. I want to create multilingualism on the site (translations will be stored in the database) Do I do the right thing on the front of json I accept in the state, and from there each component takes the values it needs? 2. If I have comments on the post on the page, then when adding a new one, do I need to send it to the state?
1 answer
- It is normal.
- There are two strategies:
- When adding, you send a new record to the database, then you take back all the records from the back to the state, the components receive updated data due to the reactivity.
- Immediately add to the state, send a new record to the database, get an answer. In case of an error in the response, you somehow signal to the user that no luck and further suggest some options: repeat the request / roll back to the state before sending. The second option, the so-called optimistic update, is more complex, but more user friendly.
|