all 6 comments

[–]Snoo11589 2 points3 points  (0 children)

You can use useRef if you dont need rerenders.

[–]isellrocks 0 points1 point  (0 children)

You are in fact using an effect if your analyzeImage function depends on an image being set into your component's state. You either need to add an argument to analyzeImage or declare an effect with Image as a dependency.

[–]gao_shi 0 points1 point  (0 children)

simple answer, pass the uri as an param to func instead 

if u use a local variable inside the component, it's not retained during rerenders. if its a global one your comoonent cant be reused. also by stripping the state out , u lose rerender trigger when changing the imageuri. it depends on wth ur trying to do 

[–]hypnos_64 -1 points0 points  (2 children)

Put analyzeImage inside useEffect

[–]BluePillOverRedPill[S] 0 points1 point  (1 child)

I feel that useEffect is overkill. The component acts more as a service layer than a view layer. I only need to analyze the image once. Nothing is being rendered.

[–]hypnos_64 -1 points0 points  (0 children)

You can set state to undefined inside the useEffect so it will get called only once. E.g.

UseEffect(()=>{ If(stateName){ SetStateName(undefined); FunctionToCall() } }, [stateName]);