Last updated 1 year ago by Ben McCormickreact
A principle of readable code:
Code should where possible be written in the order in which a reader needs to understand it.1
As an example, here is a React component that displays the time remaining in a user session based off of some cookie values. It checks a cookie on a regular interval to see whether it should display a warning about the session timeout. Once it is showing the warning, it begins checking the cookie more frequently in order to show a timeout. Once the session expires, it can stop checking.