pi-react
v0.0.2
Published
A React library for integrating the Pi SDK into React projects.
Downloads
5
Maintainers
Readme
pi-react
pi-react is a React library for integrating the Pi Network SDK into React projects easily.
Installation
npm install pi-reactUsage
Initialize the SDK
Use the usePiSDK hook to initialize the Pi SDK in your app:
import { usePiSDK } from "pi-react";
const App = () => {
const isInitialized = usePiSDK(true); // Enable sandbox mode
return <div>{isInitialized ? "SDK Initialized" : "Loading SDK..."}</div>;
};Authenticate Users
Use the PiAuth component to authenticate users:
import { PiAuth } from "pi-react";
const App = () => {
const handleAuthSuccess = (authResult) => {
console.log("Authenticated user:", authResult.user);
};
return <PiAuth onAuthSuccess={handleAuthSuccess} />;
};Handle Payments
Use the PaymentButton component to handle payments:
import { PaymentButton } from "pi-react";
const App = () => {
const handleServerApproval = (paymentId) => {
console.log("Payment ready for approval:", paymentId);
};
return (
<PaymentButton
amount={3.14}
memo="Test Payment"
onReadyForServerApproval={handleServerApproval}
/>
);
};