I ran a profiler on the following code:
function App() {
const [ counter, setCounter ] = useState(0);
return <div>
<div>{counter}</div>
<button onClick={(e) => setCounter(counter + 1)}>Inc</button>
</div>
}
Which is pretty standard, what's interesting is the unstable_runWithPriority
function.
It takes priority as a parameter but doesn't schedule anything, instead it calls the event handler.
Regardless of what the priority is, it just runs it all the same. Can someone elaborate the necessity of this function?
Shouldn't there be some sort of task or a microtask scheduled based on priority?
It sets
currentPriorityLevel
(a global variable which is used by other functions in the chain) to given priority. Runs the task and returnscurrentPriorityLevel
back to its original value.