<commit_before># Redux Persist Recipes

### Simplest Usage
```js
import { createStore, combineReducers } from 'redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import reducer from '../reducers'

const store = compose(autoRehydrate())(createStore)(reducer)
persistStore(store)
```
Stored state will be read out of localStorage and dispatched (asynchronously), autoRehydrate will use these actions to merge the stored state into the initial state.

### Delay Render Until Rehydration Complete
```js
import { createStore, combineReducers } from 'redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import reducer from '../reducers'

const store = compose(autoRehydrate())(createStore)(reducer)

export default class AppProvider extends Component {

  componentWillMount(){
    persistStore(store, {}, () => {
      this.setState({ rehydrated: true })
    })
  }

  render() {
    if(!this.state.rehydrated){
      return <div>Loading...</div>
    }
    return (
      <Provider store={store}>
        {() => <App />}
      </Provider>
    )
  }
}
```

### Blacklist & Custom Rehydration
```js
// ## app.js
import { createStore, combineReducers } from 'redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import * as reducers from '../reducers'

const store = compose(autoRehydrate())(createStore)(reducer)
persistStore(store, {blacklist: ['aTransientReducer']})

// ## someReducer.js
import { REHYDRATE, REHYDRATE_COMPLETE } from 'redux-persist/constants'

const initialState = {
  rehydrationCount: 0,
  initialized: false,
}

export default function someReducer(state = initialState, action) {
  switch (action.type) {

  case REHYDRATE_COMPLETE:
    return {...state, initialized: true}

  case REHYDRATE:
    // *important* to make sure the rehydration key matches the reducer key.
    if(action.key === 'someReducer'){

      //delete transient data
      delete action.payload.someTransientData

      //increment a counter
      var rehydrationCount = action.payload.rehydrationCount + 1

      //invalidate a cache
      var someCachedData = Date.now()-10000 > action.payload.someCachedData.time ? null : action.payload.someCachedData

      return {...state, rehydrationCount, someCachedData}
    }
    return state

  default:
    return state
  }
}
```

##React-Native
simply plug in AsyncStorage:
```js
var { AsyncStorage } = require('react-native')
import { createStore, combineReducers } from 'redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import reducer from '../reducers'

const store = compose(autoRehydrate())(createStore)(reducer)

persistStore(store, {storage: AsyncStorage}, () => {
  console.log('restored')
})
```

##Custom Action Creator
Custom action creators are one way to take action during rehydration, such as validating access tokens.
```js
import { REHYDRATE } from 'redux-persist/constants'

const rehydrateAction = (key, data) => {
  if(key === 'auth'){
    validateToken(data.token)
  }
  return {
    type: REHYDRATE,
    key: key,
    payload: data
  }
}

persistStore(store, {rehydrateAction: rehydrateAction})
```<commit_msg>Update recipes.md<commit_after># Redux Persist Recipes

### Simplest Usage
```js
import { createStore, combineReducers } from 'redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import reducer from '../reducers'

const store = compose(autoRehydrate())(createStore)(reducer)
persistStore(store)
```
Stored state will be read out of localStorage and dispatched (asynchronously), autoRehydrate will use these actions to merge the stored state into the initial state.

### Delay Render Until Rehydration Complete
```js
import { createStore, combineReducers } from 'redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import reducer from '../reducers'

const store = compose(autoRehydrate())(createStore)(reducer)

export default class AppProvider extends Component {

  componentWillMount(){
    persistStore(store, {}, () => {
      this.setState({ rehydrated: true })
    })
  }

  render() {
    if(!this.state.rehydrated){
      return <div>Loading...</div>
    }
    return (
      <Provider store={store}>
        {() => <App />}
      </Provider>
    )
  }
}
```

### Blacklist & Custom Rehydration
```js
// ## app.js
import { createStore, combineReducers } from 'redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import * as reducers from '../reducers'

const store = compose(autoRehydrate())(createStore)(reducer)
persistStore(store, {blacklist: ['aTransientReducer']})

// ## someReducer.js
import { REHYDRATE, REHYDRATE_COMPLETE } from 'redux-persist/constants'

const initialState = {
  rehydrationCount: 0,
  initialized: false,
}

export default function someReducer(state = initialState, action) {
  switch (action.type) {

  case REHYDRATE_COMPLETE:
    return {...state, initialized: true}

  case REHYDRATE:
    if(action.payload.someReducer){
      var newState = action.payload.someReducer

      //delete transient data
      delete newState.someTransientData

      //increment a counter
      var rehydrationCount = newState.rehydrationCount + 1

      //invalidate a cache
      var someCachedData = Date.now()-10000 > newState.someCachedData.time ? null : newState.someCachedData

      return {...state, ...newState, rehydrationCount, someCachedData}
    }
    return state

  default:
    return state
  }
}
```

##React-Native
simply plug in AsyncStorage:
```js
var { AsyncStorage } = require('react-native')
import { createStore, combineReducers } from 'redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import reducer from '../reducers'

const store = compose(autoRehydrate())(createStore)(reducer)

persistStore(store, {storage: AsyncStorage}, () => {
  console.log('restored')
})
```
{'fraction_non_alphanumeric': 0.12435411643127799, 'fraction_numerical': 0.002411298656562177, 'mean_word_length': 4.120811287477954, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2919605', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1775, 'n_words': 474}