I recently found a function in some code that I'm analyzing but I don't understand what's going on.
In this function I have an if with a condition and then a return.
if (condition) return
In this if there are no keys {} that determine the scope of the if.
I've seen cases where we have the if with the keys {} and inside it we have the return that can even be a component.
In that case what is happening in this if? I noticed that the statement I call after the if doesn't happen even with the condition returning TRUE, but the setState is working.
const fireScreenDisplayed = (props = {}) => {
_checkScreenValidity()
if (checkDone && done && !props.force) return
setDone(true)
publishCdmEvent(_buildEvent('ScreenDisplayed', props))
}
See that after the return we have the setState and below it a function.
This if returns the function too?
What is returning from this if?
I want to understand this technique and why it is used and if there are alternatives.