📎 Webclip
How to Add Browser Notifications to Your React App
The page shows how to use the HTML5 Notification API in a React app and how to rely on react-web-notification to display native popup notifications and handle notification events. It also builds a password manager that shows notifications when passwords are added, edited, copied, or deleted.
Reading notes#
- Browsers can display native popup notifications with the HTML5 Notification API, including text, icons, and sound.
- Users must grant permission before a web app can show browser notifications.
- React-Web-Notification is presented as a React component for showing popups and handling click, permission granted, and permission denied events.
- The example app is a password manager built with React.
- Create React App is used to start the project.
- The app uses Axios for HTTP requests, Formik and Yup for forms and validation, MobX for state management, React Bootstrap for styling, React-Copy-To-Clipboard for clipboard actions, and React Router for routing.
App.jsadds a React Bootstrap navbar and a route to the home page.HomePage.jsrenders a table of passwords, modal dialogs for adding and editing entries, and buttons for copying usernames and passwords, editing entries, and deleting entries.- Notifications are shown when a username or password is copied and when an entry is deleted.
PasswordForm.jsuses Formik and Yup to validate name, URL, username, and password fields, then calls add or edit requests and refreshes the store.requests.jsdefines GET, POST, PUT, and DELETE calls to a local backend athttp://localhost:3000.store.jsdefines a MobX store with a passwords array and a setter action.index.htmlchanges the page title and adds Bootstrap CSS.- The app is run on a different port from the backend, and the backend is served with json-server using
db.jsonwith an empty passwords array.
