matejs
matejs

Reputation: 163

Getting data from fetch and not storing it in state

We have a React/Redux application where you can change language of the application and get all the strings for it from the API with fetch. Storing all the strings in the state seems like a bad idea, storing only the language (en, es, etc.) in state and strings elsewhere seems like a better one.

So is there a way to save data fetched in action from API call and not save it in state?

Upvotes: 3

Views: 1281

Answers (1)

danielepolencic
danielepolencic

Reputation: 5163

If you don't want to use the store then you should not use an action to fetch for the data.

You could store the translation somewhere else and just reference them from the state. If you decide to go down this route, the easiest option is not to use the store and fetch the translation outside of redux (i.e. no action).

The other option is to store the translations in the state. You might not like it, but it's perfectly viable. Storing all the state in one single object has its benefits (time travel, debugging, etc.).

I don't think there's a clear cut in this scenario.

Also, there's an interesting discussion about storing all or partial state in the store on Github.

Upvotes: 1

Related Questions