Closed mihir0x69 closed 8 years ago
This is my code. When I call add() method, the data gets stored but it can be seen after I perform add() once again.
var React = require('react-native'); var { StyleSheet, View, Text } = React; var Store = require('react-native-store'); var DB = { foo: Store.model('foo') }; module.exports = React.createClass({ getInitialState: function(){ return{ items: null, string: '' } }, render: function(){ return( <View style={styles.container}> <Text onPress={this.onButtonPress}>Add Item</Text> <Text onPress={this.destroyData}>Destroy</Text> <Text>{this.state.string}</Text> </View> ); }, onButtonPress: function(){ DB.foo.add({ fname: 'Mihir', lname: 'Karandikar' }); DB.foo.find() .then((response) => this.setState({ items: response, string: JSON.stringify(response) })); console.log(this.state.items); }, destroyData: function(){ DB.foo.destroy(); }, }); var styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#eaeaea', alignItems: 'center', justifyContent: 'center' } });
When I console.log this shows up:
adding item... null adding item... null adding item... [Object]0: Object length: 1 __proto__: Array[0]
It was happening because of setState() method. Closing. And thanks for this cool repo.
This is my code. When I call add() method, the data gets stored but it can be seen after I perform add() once again.
When I console.log this shows up: