mst-persist icon indicating copy to clipboard operation
mst-persist copied to clipboard

Persist Array in React Native

Open gHashTag opened this issue 4 years ago • 0 comments

Why if I add mst-persist all keys are kept except finishArr which becomes an empty string?

Isn't it possible to store arrays in it?

const Dice = types
.model('Dice', {
    startGame: types.boolean,
    count: types.number,
    players: types.number,
    message: types.string,
    multi: types.number,
    finishArr: types.array(types.boolean)
  })
  
const DiceStore = Dice.create({
  startGame: false,
  count: 6,
  players: 1,
  message: ' ',
  multi: 0,
  finishArr: [true, true, true, true, true, true]
})

persist('@DiceStore', DiceStore, {
  storage: AsyncStorage, // AsyncStorage for React-Native, localStorage for web
  jsonify: true, // Set to true if using AsyncStorage
  whitelist: ['startGame', 'count', 'players', 'message', 'multi', 'gamer', 'finishArr'] // only these keys will be persisted
})

gHashTag avatar May 07 '21 10:05 gHashTag