Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store [String] or [Int] in react-native realm

I've read online where in Android/iOS I should inherit from RealmObject and create my own RealmString to use as my objectType in a list.

What's the approach in react-native? I can't find any code samples on how to handle this issue.

Thanks

like image 298
Daniel Gary Avatar asked Oct 18 '22 12:10

Daniel Gary


1 Answers

You can use the same strategy in react-native:

var intObject = {
  name: 'intObject',
  properties: { value: 'int' }
};

var intListObject = {
  name: 'intListObject',
  properties: { 
    'intList': { type: 'list', objectType: 'intObject' } }
};

var realm = new Realm({schema: [intObject, intListObject]});

var listObject = realm.create('intListObject', { 
  intList: [{value: 0}, {value: 2}, ...]
});

var value = listObject.intList[1].value; // 2

We plan to support arrays of primitive types without the extra abstraction but there isn't yet an eta for this feature.

like image 167
Ari Avatar answered Oct 22 '22 03:10

Ari