Skip to content
Advertisement

How to get value of useState variable in function that passed to another component

The best way to describe question is my code:

JavaScript

So i have params variable, that im init with object, that i’m getting async from firebase. Implementation of initializing you can see in useEffect method. For every object i want to pass ref for the function “fieldChangedHandler”, for managing value of inputs.

fieldChangedHandler is a method of my EstateParamsList. But there i cant get value of params!

Question is WHY? I’m calling fieldChangedHandler only after everything was rendered, and async request was done.

Below is console log of params. Why in func is empty params?

enter image description here

Calling:

JavaScript

Advertisement

Answer

Why not use curried function?

JavaScript

When you call the change function you should already have the right values in scope:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement