[react native] realm.write is not a function

I’ve been stymied why I cannot get my app to recognize my wrapper function for Realm.write().

Here is a gist that covers what code is involved in the execution. My openDb() wrapper appears to work,

name: "Brand"
brandName: "string"
color: "string"
icon: "string"
textColor: "string"

But when I try to write to the db I get
ExceptionsManager.js:76 TypeError: _realm.default.write is not a function
This is my first attempt to actually incorporate Realm into our existing app. This Realm demo has a quick expected turnaround (next 24hrs). So any help is most appreciated.

UPDATE: After messing around with the API calls, I imported realm directly into my App.js to test it. I found that not only was write() failing, but the isClosed boolean registered as undefined.

When I logged the call, console.log('realm is closed?', Realm.isclosed);, it returned realm is closed? undefined. So, still don’t know what’s going on here.

I’ve updated the gist so, hopefully, others won’t have to struggle with the multiple vectors of 1. learning this API, 2. translating the current example in the doc to ES7+, and 3. scouring the Internet for guidance.

A couple of points:

  • It wasn’t apparent to me that creating a new Realm also opens it. It took me a long time to resolve that issue because it wasn’t documented.

  • Using the symbol realm interchangeably is bad practice and confusing. Assuming folks understand that Realm is not realm, other than knowing that JS is case-sensitive is not helpful. Using unambiguous symbols is JS 101. The updated version uses Realm only twice: once to import and then to construct the instance.

More “learn as you go” issues. I’ll close.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.