H
H
HellYeahOmg2019-12-02 20:08:42
React
HellYeahOmg, 2019-12-02 20:08:42

How to make the function see actual props?

There is some component that accepts a certain prop, which can change during life.
Inside the component, an object from the library is initialized, which takes a function in onerror.
In this function, prop and some logic are already used further, the problem is that the function uses the original value of the prop and does not see the changes.
I will write an abstract code for an example:

The code

const Component = ({someProp}) => {
  useEffect(() => {
     // инициализация библиотечного объекта, который принимает ф-цию обработчик ошибок
      object.init({onerror: handleError})
}, [])
  const handleError = () => {
     // в зависимости от значения пропа делать что-то
     if (someProp) ...
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question