When run below code i get this output:
render home
equal values
not equal values
What am i missing?
// code goes here
import React, {useEffect} from 'react';
import {View} from 'react-native';
import {cond, eq, Value} from 'react-native-reanimated';
const val = new Value(10);
const val2 = new Value(5);
const Home = () => {
useEffect(() => {
cond(
eq(val, val2),
console.log('equal values'),
console.log('not equal values'),
);
}, []);
console.log('render home');
return <View style={{flex: 1}}></View>;
};
export default Home;
Hi @erkangozukucuk,
it seems you're mixing reanimated nodes with JS code, so the result may be surprising.
It works as expected, because you use cond node (which is a function from JS side), so JS evaluates arguments:
eq nodeconsole.logs evaluates to undefined and prints text on the console as a side effectTry it yourself by adding:
const some_function = () => {
console.log('eq');
return 5;
};
and changing nodes to:
cond(eq(val, val2), some_function(), console.log('not equal values'));
If you have any further concerns don't hesitate to reopen.
Most helpful comment
Hi @erkangozukucuk,
it seems you're mixing reanimated nodes with JS code, so the result may be surprising.
It works as expected, because you use
condnode (which is a function from JS side), so JS evaluates arguments:eqnodeconsole.logsevaluates toundefinedand prints text on the console as a side effectTry it yourself by adding:
and changing nodes to:
If you have any further concerns don't hesitate to reopen.