
The bootloader pattern for app initialization in React
If you’re using React to build a web app or a React Native mobile application, chances are your app has a handful of initialization tasks: things that always need to happen before the main application mounts and runs. Some examples of these responsibilities include: Loading previously-saved settings. Creating global-ish objects, like a single shared API_CLIENT instance. Deciding whether the user is logged in, and fetching their current profile if so. Checking whether there is a newer version of the application available. For this type of work, there’s a handy pattern I always end up using, which leverages React Context Providers to streamline things. I call it the “bootloader pattern” because it reminds me of what low-level hardware bootloaders do to start up real machines, but that’s just my cute name for it. ...