Getting started with web monetization in React
After seeing the announcement for the Grant For The Web Hackathon I did a little bit of digging and thinking to try and understand web monetization better.
If you’re looking to create something using React, hopefully this quick guide can save you a bit of time in getting started.
Creating a hook to see if a user is web monetized
Here’s a hook that will return you two states - isMonetized
and isLoading
:
You would be able to use it like this:
How to test your web monetization without signing up for Coil
The test-web-monetization provides a bookmarklet you can use to test your project (scroll down to the Bookmarklet for Testing section of the page). This makes it super easy to test web monetization - and it will work with the React hook I’ve described above too.
This does also mean that if you do set up web monetization this way, anyone will be able to easily get around it by using a bookmarklet such the one listed above. As of now there are no server-side examples on the Web Monetization website, but hopefully there will be some soon!
Other resources
If you are planning on using React or Gatsby, there are some small packages that may help you out:
I’m super excited to see what everyone comes up with for this hackathon! Good luck!