Realm React native contain query updating react ui with wrong results


#1

-2

I am using Realm react native(latest version 2.29.1) in an app. I have a strange problem when I try to filter the objects that it returns. When I type something in the search textInput it is supposed to refine that query with the new state and show me the search results. But what happens is it shows me the wrong data. I should also note that in console log everything is fine, its just that in the ui flatlist is not updated with proper items. I should also mention that I have tried adding listener or using separate variables for updating states or even using redux props but all are the same. The only time the query works in the ui is that if I type the wrong search item( no items matching) and then type the right search term afterward and then it’s fine. So here is my code

const Realm = require("realm");
class ActiveJobsScreen extends Component {
constructor(props) {
    this.state = {
        realm: [],
        searchText: ''
    };
    Realm.open(allJobsDBOption).then(realm => {
        this.setState({realm})
    })
}

render() {
    return (
        <View>
            <TextInput
              style={{height: 40, borderColor: 'gray', borderWidth: 1}}
              onChangeText={(text) => this.setState({searchText})}
              value={this.state.searchText}
            />
            <FlatList
                data={this.state.realm.objects('jobData').filtered(`description CONTAINS[c] $0 `, this.state.searchText)}

                renderItem={({item, index}) => this.renderJob(item, index)}
                keyExtractor={(item, index) => index.toString()}
            />          
        </View>
    )
  }
renderJob(item, index){
   return (
      <Text>Job description{item.description}</Text>
   )
  }
 }
}