Unable to pass props through passProps on route initialization.
I'm using WatermelonDB for offline support. And i should pass database property on initialization, but currently i'm having issues with it.
Navigation.setRoot({
root: {
options: {},
stack: {
children: [
{
component: {
id: 'SplashPage',
name: 'SplashPage',
passProps: {
database // <--- It's always throws an error
}
},
},
],
options: {
topBar: {
visible: false,
animate: false,
drawBehind: true,
},
},
},
},
});

I remember having issues passing MobX State Tree models to screens in v1 of RNN. I can't remember the exact error, but I had resorted to doing something like:
passProps: {
getDatabase: () => database
}
It's not ideal by any means, but it's worth trying so you're not stuck for the time being.
I believe this issue will be resolved once we stop passing props over the bridge. We already save options in js as they aren't serializable, we just need to omit them when processing options
https://github.com/wix/react-native-navigation/blob/v2/lib/src/commands/OptionsProcessor.ts#L35
https://github.com/wix/react-native-navigation/blob/v2/lib/src/commands/OptionsProcessor.ts#L45
@Necromant1k btw can't you use React context to pass Database deep into the component tree?
@radex Passing a model via passProps causes an issue with observed collections: Record ID was sent over the bridge, but it's not cached
...
passProps: {
model: () => model
}
...
using above function works though. not sure if this is a bug in watermelondb or RNN, but took me forever searching issues on watermelondb and finally stumbled on to this thread.
Might be useful to add a note in the watermelondb docs about the above workaround. If I find time this week I could make a PR if you think it's appropriate
It's happening for me on 0.59.8 too. Reason for this was that I was calling the native method with an object that contains a field with NaN value.
SomeNativeModule.someMethod({number:NaN}) // crashed for me
Adding a safe check resolved it for me.
Ideally, I think it should not crash :( and handle these cases
@vardaan please can you explain exactly how you fixed this please. That description was confusing for me
@vardaan please can you explain exactly how you fixed this please. That description was confusing for me
@dihan you have just to check for NaN value. For example isNaN(myvalue). And if it's NaN just provide default value for example 0
We did exactly what @Necromant1k said I m sorry for replying late