Hooks for integrating React with Web Monetization.
As I am no longer an employee of Coil, this repo will likely no longer be maintained. If you'd like to maintain this repo please leave an issue.
$ npm install react-hook-wm
or
$ yarn add react-hook-wm
Returns the current monetization state.
Returns the latest paymentPointer/requestId received from any monetization event.
Returns the latest paymentPointer/requestId received from any monetization event.
Exposes a more React-ish way of interacting with monetization events through the following interface:
interface UseListenerOptions {
onPending?: (event: MonetizationPendingEvent) => void
onStart?: (event: MonetizationStartEvent) => void
onProgress?: (event: MonetizationProgressEvent) => void
onStop?: (event: MonetizationStopEvent) => void
}
Attaches the provided reducer to events from useListener and returns the state produced. See the source for useCounter or the source for useHasPaid for examples.
Returns the last assetCode (code) and the sum of the amounts (total) received from monetizationprogress
events.
Alternative to useCounter that requires a CounterProvider in one of its parent components. Allows for tracking prior to using the hook.
Returns a Boolean indicating whether or not the payment pointer has been paid yet. Useful for determining requesting for pay-locked content is ready.
Alternative to useHasPaid that requires a HasPaidProvider in one of its parent components. Allows for tracking prior to using the hook.
Provides useCounterContext's value. It's recommended that its children are memoized using React.memo
.
Provides useHasPaidContext's value. It's recommended that its children are memoized using React.memo
.