title: Using redux with a local database
body: <p>I have an offline React web app where all data is stored locally in indexedDB. There is no server other than the file hosting for static assets. I am getting to the point where I am starting to look into using redux now but I am trying to understand the tradeoffs between moving more data into the store and continuing to rely on the DB. What's the idiomatic way of using a local db with redux?</p>
  
  <p>Currently my app is composed of several container components that each fetch data from the db in <code>componentWillMount</code>. One option for integrating redux is to keep this mostly the same, with the only difference being the state is kept in the store and data is fetched using actions and thunks.</p>
  
  <p>Alternately, I have seen lots of example code that loads all the data into the store at launch. This makes the whole app more deterministic, easier to test and reproduce. Switching between the main components would happen instantly (at the expense of initial app load). But I lose the benefits the DB provides like indexes and nice queries.</p>
  
  <p>It seems like it would be unreasonable load literally the whole db into the store, at least in my case, that would be about 10MB of data, maybe more. So I will always have at least some components which will need to continue fetching their data on mount. But there's a subset of data which is central to the app and can be argued that table should be loaded in its entirety (this would be about 5,000 to 10,000 objects, probably).</p>
  
  <p>What's the idiomatic way to work with local storage and redux? I get the sense that async fetches in <code>componentWillMount</code> is not idiomatic if it can be avoided. Even in instances where the state is small enough that it can be fully loaded into the store, is it worth giving up the benefits of a nice efficient query interface?</p>
  
  <hr>
  
  <p>Edit: I should mention: I am using <a href="https://github.com/dfahlander/Dexie.js" rel="noreferrer">Dexie</a>, which is a really, really wonderful library for working with indexedDB. It's fast, has a nice query interface, handles migrations etc... I'd really like to continue using Dexie unless there's a really strong reason to do otherwise.</p>
  
  <p>For reference, <a href="https://github.com/dfahlander/Dexie.js/issues/553" rel="noreferrer">here's</a> a discussion on this topic on Dexie's github. The general take away form that is "it depends". Not quite the answer I was looking for, so I am hoping to get more insight if possible.</p>