⚛️ React.js & Next.js Integration
Iranian Rial Exchange Rate Calculator Widget for React Applications
Quick Start Guide
Copy the React component below and start displaying real-time Iranian Rial exchange rates in your React or Next.js application!
// React Component Example
import { useEffect } from 'react';
const PashiziWidget = ({ currency = 'usd', lang = 'en' }) => {
useEffect(() => {
const script = document.createElement('script');
script.src = `https://www.pashizi.com/widget/?lang=${lang}&base=${currency}`;
script.async = true;
document.body.appendChild(script);
return () => {
document.body.removeChild(script);
};
}, [currency, lang]);
return <div data-pashizi-widget data-lang={lang} data-base={currency} />;
};
return PashiziWidget;🎮 Interactive React Demo
Try different currency and language combinations to see how the React component works with live previews and get the exact code.
Customize & Preview Live
Choose your preferred currency and language to see the widget in action. Copy the integration code for your setup.
Live Widget Demo
📋 Integration Code
import PashiziWidget from './PashiziWidget';
function MyComponent() {
return (
<div>
<PashiziWidget currency="usd" lang="en" />
</div>
);
}
export default MyComponent;💡 Make sure you have the PashiziWidget component created in your project.
Show PashiziWidget Component Code
"use client";
import { useEffect } from "react";
interface PashiziWidgetProps {
currency?: string;
lang?: string;
className?: string;
}
const PashiziWidget = ({
currency = "usd",
lang = "en",
className = ""
}: PashiziWidgetProps) => {
useEffect(() => {
const script = document.createElement("script");
script.src = `https://widget.pashizi.com/calculator?currency=${currency}&lang=${lang}`;
script.async = true;
script.defer = true;
document.body.appendChild(script);
return () => {
if (document.body.contains(script)) {
document.body.removeChild(script);
}
};
}, [currency, lang]);
return (
<div
data-pashizi-widget
data-lang={lang}
data-base={currency}
className={className}
/>
);
};
export default PashiziWidget;📝 Usage Examples
<PashiziWidget /><PashiziWidget currency="eur" lang="de" /><PashiziWidget lang="fa" currency="usd" /><PashiziWidget currency="eur" lang="fr" />▲ Next.js Specific Configuration
📁App Router (Next.js 13+)
Add "use client" directive at the top of your component for client-side rendering:
"use client";
import { useEffect } from "react";
const PashiziWidget = ({ currency, lang }) => {
// Component implementation...
};🏗️Pages Router (Next.js 12 and below)
Use dynamic imports to ensure the component only runs on the client:
import dynamic from 'next/dynamic';
const PashiziWidget = dynamic(() => import('../components/PashiziWidget'), {
ssr: false
});⚙️ Advanced Configuration
Component Props
| Prop | Type | Description | Example |
|---|---|---|---|
| currency | string | Base currency code (3 letters) | "usd" |
| lang | string | Interface language (2 letters) | "en" |
| className | string? | Optional CSS classes | "my-widget" |
TypeScript Interface
Define proper TypeScript interfaces for better type safety:
interface PashiziWidgetProps {
currency: string;
lang: string;
className?: string;
}
const PashiziWidget: React.FC<PashiziWidgetProps> = ({
currency,
lang,
className
}) => {
// Component implementation...
return (
<div
data-pashizi-widget
data-lang={lang}
data-base={currency}
className={className}
/>
);
};💰 Supported Currencies (28+)
Use these currency codes in the 'currency' prop. All rates are displayed against Iranian Rial (IRR).
💡 Usage Example
<PashiziWidget currency="eur" lang="en" />usdeurgbpjpychfcadaudsgdhkdnoksekdkkmyrrubtryinrcnyaedthbqarsaromrbhdkwdiqdaznafnamd🌍 Supported Languages (10)
Use these language codes in the 'lang' prop to display the widget interface in different languages.
💡 Language Selection Example
<PashiziWidget currency="usd" lang="fa" />This displays USD rates with Persian (Farsi) interface. Persian and Arabic support right-to-left (RTL) layouts.
enfadearesfritnlruzh✅ Best Practices
✅Do
- Use useEffect for script loading and cleanup
- Add dependency array [currency, lang] to useEffect
- Use "use client" directive for Next.js App Router
- Define proper TypeScript interfaces
- Test on different screen sizes
❌Don't
- Don't forget script cleanup in useEffect return
- Don't use same currency-language combination twice on one page
- Don't load scripts directly in render function
- Don't hard-code currency and language values
- Don't skip TypeScript types for better maintainability
⚠️ Important Notes
- Only one widget with a specific language and currency combination is allowed per page. For example, if there is already a widget with currency='usd' and lang='en' on the page, a second widget with the same combination will not work.
- To display multiple widgets, use different currency or lang props for each widget.
- The script URL parameters are automatically generated based on the props you pass to the component.
- For Next.js 13+ App Router, always add "use client" directive to enable client-side rendering.
- The widget automatically adapts to your website's styling and is fully responsive.