You can not stop useEffect
run when the component first mounted, but you can do the condition checking to run your code inside it like this:
useEffect(() => {
// Only run when stringProp has value, you might have different condition, add them there
if(stringProp){
// do something
}
}, [stringProp]);
Updated: If you might set stringProp back to the initial value, you can do use useRef
to control first time run like this
const isFirstTimeOfUseEffect = useRef(true)
useEffect(() => {
// Only run when stringProp has value, you might have different condition, add them there
if(!firstUseEffectRun.current){
// do something
}else{
firstUseEffectRun.current = false
}
}, [stringProp]);