question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing object of type * which has been invalidated or deleted.

See original GitHub issue

Hello everyone!

Goals

I am trying to get values from my realm and print them in a flatlist in react native

Expected Results

I would expect it to print my flatlist without any issues.

Actual Results

The error : Accessing object of type ListIncomes which has been invalidated or deleted. But when I check if my object is valid, (isValid()), I get true, I can even make a console.log with it.

Steps to Reproduce

First, I created a first Realm that I modified just to add an id. I also changed the name of ListIncomeSchemaOk and ListIncomes but it doesn’t change anything. Weirdest thing is that the text “TEST” is written on my app and is printed on my screen just before the error comes. It seems logical since I can make a console.log(Array.from(realm.objects(‘ListIncomes’))) and the right thing is printed.

Code Sample

The definition of my realm: const ListIncomeSchemaOk = { name: 'ListIncomes', properties: { id: 'string', charterer: 'string', type: 'string', tonage: 'float', price: 'float', from: 'string', to: 'string', fromyear: 'int', frommonth: 'int', fromday: 'int', toyear: 'int', tomonth: 'int', today: 'int' } };

When I try to get my values:

componentDidMount(){ Realm.open({schema: [ListIncomeSchemaOk], schemaVersion: currentVersion}) .then(realm => { this.setState({listItems: Array.from(realm.objects('ListIncomes'))}) realm.close(); }) .catch(error => { console.log(error); }) }

And in the render:

<FlatList data={this.state.listItems} keyExtractor={(item) => item.id} renderItem={({item}) => <Text>TEST</Text>} />

Version of Realm and Tooling

  • Realm JS SDK Version: 4.0.0-beta.0
  • Node or React Native: react-native-cli: 2.0.1 and react-native: 0.61.5
  • Client OS & Version: Windows 10 PRO 1909
  • Which debugger for React Native: ?/None

I am pretty sure it is a stupid error but I checked others similar issues on github and stack but all add an issue with navigation (but I don’t have any navigation on my file) or with the validity but my object is valid… I really don’t understand and it’s making me crazy! Sorry if it is a stupid error Thanks in advance and have a nice evenning 😃

EDIT: Actually it was an issue with me closing realm too soon, so now I close it in the componentWillUnmount

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
angelo558commented, Jun 27, 2020

Yes, as I said in the edit I was closing realm too soon. now I only close it on componentWillUnmount

Sent from my MI 5s On ebrahimhassan121 notifications@github.com, 27 Jun 2020 8:07 pm wrote:

@angelo558https://github.com/angelo558 did you find a solution

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/realm/realm-js/issues/2765#issuecomment-650593755, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AO5LOWQ2CITRI5FTCW23ZDLRYYYOFANCNFSM4LSDU4WQ.

0reactions
takameyercommented, Jun 3, 2022

@Joshfindit That tutorial is out of date. We now have a package called @realm/react that handles this better. Try it out and let us know what you think! https://github.com/realm/realm-js/tree/master/packages/realm-react

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accessing object of type X which has been invalidated or ...
It seems that if you pass an object to navigation, delete this object (while the object is still in the navigation stack), -...
Read more >
realm.js - Accessing object of type Contact which has been ...
Here is the code I'm using, which, after delete get an exception - "Accessing object of type Contact which has been invalidated or...
Read more >
Procedure when object is invalidated - Realm
The Object has been deleted or invalidated error will occur if an object has been deleted from a Realm, but you subsequently try...
Read more >
Accessing object of type info_data which has been invalidated ...
Coding example for the question Accessing object of type info_data which has been invalidated or deleted realm in react native-React Native.
Read more >
Realm object invalidated
Realm object invalidated. It happens because as soon as the realm is closed, all access to data, which in current case is Results,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found