While using multiple state variables in my App.jsx I wanted to set the value of one state equal to that of another state.
const [exchangeRatio, setExchangeRatio] = useState();
const [toCurValue, setToCurValue] = useState();
function foo()
{
setToCurValue(exchangeRatio);
}
On console.log(exchangeRatio);
{exchangeRatio: undefined}
exchangeRatio: undefined
__proto__:
constructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
valueOf: ƒ valueOf()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()
On further
console.log({exchangeRatio}.valueOf());
>>Undefined
I am new to React if there are ways to do the same feel free to write.