redux-persist blacklist와 nested-persist 차이

윤수호·2022년 6월 21일
0

BLACKLIST,WHITELIST

blacklist는

// BLACKLIST
const persistConfig = {
  key: 'root',
  storage: storage,
  blacklist: ['navigation'] // navigation will not be persisted
};

// WHITELIST
const persistConfig = {
  key: 'root',
  storage: storage,
  whitelist: ['navigation'] // only navigation will be persisted
};

이런식으로 persist를 적용하지 않을 것을 지정해 줄 수 있는 방법이다.

하지만 전부가 아닌 좀더 자세히 지정을 하고 싶으면 nested-persist 라는 방법을
사용할 수 있는데 이방법은 쉽게 말해서 중첩해서 사용하는 방법이다.

import { combineReducers } from 'redux'
import { persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

import { authReducer, otherReducer } from './reducers'

const rootPersistConfig = {
  key: 'root',
  storage: storage,
  blacklist: ['auth']
}

const authPersistConfig = {
  key: 'auth',
  storage: storage,
  blacklist: ['somethingTemporary']
}

const rootReducer = combineReducers({
  auth: persistReducer(authPersistConfig, authReducer),
  other: otherReducer,
})

export default persistReducer(rootPersistConfig, rootReducer)

위의 방법을 보면 blacklist로 지정한것을 다시 지정해 안에 있는 특정 값만을
지정했는데 이러한 방법을 nested-persist 라고한다.

profile
기술블로그 시작

0개의 댓글