Because I don't know from where your funcB is called, I leave its declaration as is.
By placing and calling the funcA in a useEffect with the right dependency, in this case your obj variable, the effect is that funcA gets called everytime the obj state changes.
const [obj, setObj] = useState({})
const funcB = (v) => {
setObj(v)
}
useEffect(() => {
// funcA should be placed in this useEffect
const funcA = () => {
ajax(obj)
}
funcA();
}, [obj]);
Did you consider using useEffect ?
I think you can use useEffect here. You can read in the section : https://reactjs.org/docs/hooks-faq.html#is-it-safe-to-omit-functions-from-the-list-of-dependencies
on how to use it in declaring and calling your funcA function such that it gets called only when the obj state changes.
Because I don't know from where your funcB is called, I leave its declaration as is.
By placing and calling the funcA in a useEffect with the right dependency, in this case your obj variable, the effect is that funcA gets called everytime the obj state changes.
Because there are many places to modify obj, but I only want to call the funcA after a certain modification, useEffect is not appropriate
For example, there is a page to query the list according to conditions. It looks like this
Now we add a function to obtain conditions from the server during initialization
In this case, listData will be called twice during initialization. Obviously, the first time is useless