Using the Notifier Component
To use the Notifier
component, edit the src/App.js
file to read like this:
The App.js
component has one state, offline
, which specifies whether the app is in offline mode. By default, the state is false
. When App.js
is mounted, the componentDidMount
function, which is executed when the app is loaded, listens for the online/offline event and updates the App.js
state accordingly.
The render
function defines the layout of the app and the Notifier
component, passing the offline state as a property to Notifier
for display.
Fetch the Cloudinary logo from the Cloudinary site and save it in your src
directory as logo.png
.
Now you might wonder how all that is displayed in the app. In the src/index.js
file, the App
component is rendered on a <div>
tag with the ID root
, as follows:
To view your app, first run this command on your development server:
Afterwards, go to http://localhost:3000
on your browser to display the app. Toggle your Internet connection and you will see one of the two versions on display, depending on whether you are online or offline. See below.
Last updated