pi-react
is a React library for integrating the Pi Network SDK into React projects easily.
npm install pi-react
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>;
};
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} />;
};
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}
/>
);
};