Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: [withObservable] Value passed to withObservables doesn't appear to be observable. See console for details #1740

Open
arun-saleth opened this issue Jan 21, 2024 · 1 comment

Comments

@arun-saleth
Copy link

component:

import React from 'react'
import { withObservables } from '@nozbe/watermelondb/react'

import { StyleSheet, Text, View } from 'react-native'

async function Postcomp({post}) {
// console.log(post,'pors')
console.log(post,'post')
return (
<>
<View style={{flexDirection:'row'}}>
id
title
subtitle
body
is_pinner

  <View style={{flexDirection:'row'}}>
      <Text style={styles.cell}>id</Text>
      <Text style={styles.cell}>title</Text>
      <Text style={styles.cell}>subtitle</Text>
      <Text style={styles.cell}>body</Text>
      <Text style={styles.cell}>is_pinner</Text>
  </View>
 </>

)
}

const styles =StyleSheet.create({
cell:{
borderWidth:0.5,
borderColor:'gray',
padding:10
}
})
const enhance = withObservables(['post'], ({ post }) => ({
post
}))
export default enhance(Postcomp)

Modal

import { Model } from '@nozbe/watermelondb'
import { field, text } from '@nozbe/watermelondb/decorators'
// import { database } from '../config'

export default class Post extends Model {
static table = 'posts'
static associations = {
comments: { type: 'has_many', foreignKey: 'post_id' },
}

@text('title') title
@text('body') body
@field('is_pinned') isPinned

}

App.js

import React, { useEffect } from 'react';
import {
SafeAreaView,
StatusBar,
StyleSheet,
Text,
TouchableOpacity,
} from 'react-native';
import Postcomp from './components/Postcomp';
import { database } from './db/config';

function App() {
const addNewPost = async() =>{
await database.write(async() => {
await database.get('posts').create(post => {
post.title = 'New post'
post.body = 'Lorem ipsum...'
})
})
}

const postsCollection = database.get('posts')

return (


Add


);
}

export default App

@rahulreddyRR
Copy link

the component is not async and if you want to access that withObservables use it in this way :
const enhance = withObservables([], () => ({ post: postsCollection.query() }))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants