1
我正在測試出Realm
並希望使我的簡單程序工作。我遵循所有的官方文檔(https://realm.io/docs/javascript/latest/#getting-started)開始,但一些我仍然得到這個error說我需要運行react-native link realm
我已經完成。我運行了反應本地鏈接領域,但仍然出現錯誤
我該如何解決這個問題?
這裏的index.ios.js
文件:
import React, { Component } from 'react';
import {AppRegistry, View} from 'react-native';
import Database from './components/Database';
export default class Realm extends Component {
render() {
return (
<View>
<Database/>
</View>
);
}
}
AppRegistry.registerComponent('Realm',() => Realm);
這是我的Database.js
文件:
import React, { Component } from 'react';
import {Text, View} from 'react-native';
const Realm = require('realm');
class Database extends Component {
render() {
let realm = new Realm({
schema: [{name: 'Dog', properties: {name: 'string'}}]
});
realm.write(() => {
realm.create('Dog', {name: 'Rex'});
});
return (
<View>
<Text>
Count of Dogs in Realm: {realm.objects('Dog').length}
</Text>
</View>
);
}
}
export default Database;