Free widgets / Install guides / React and Next.js
JavaScript framework · install guide
Economic Calendar Widget for React and Next.js
Render the widget element in a component and load the script once. The script finds widget elements added after the page loads. The widget is free with attribution, needs no API key and updates itself from official-source data.
What you need
- A React or Next.js app
- The component below
Add the widget to React and Next.js
- Create a widget componentAdd the component below. It renders the widget element and loads the script once for the whole app.
- Set the options as attributesChange the data-fxmd attributes to pick the widget, currencies and theme. The options reference lists every attribute.
- Render it where the widget belongsUse the component in any page or layout. It fills the width of its container.
- DeployNo API key or server code is involved, so the component works in static exports and server-rendered apps alike.
Code for this platform
EconomicCalendar.jsx
import { useEffect } from "react";
const LOADER = "https://fxmacrodata.com/static/js/fxmacrodata-widget.js";
export default function EconomicCalendar() {
useEffect(() => {
if (window.FXMacroDataWidgets) {
window.FXMacroDataWidgets.render();
} else if (!document.querySelector(`script[src="${LOADER}"]`)) {
const script = document.createElement("script");
script.src = LOADER;
script.async = true;
document.body.appendChild(script);
}
}, []);
return (
<div
data-fxmd-widget-type="economic-calendar"
data-fxmd-currencies="USD,EUR,GBP"
data-fxmd-theme="auto"
data-fxmd-height="560"
/>
);
}
Tips for React and Next.js
- In Next.js the widget is a client component. Add the use client directive at the top of the file when using the App Router.
- The script renders each element once. To change a widget's options later, render a new element, for example by giving the component a new key.
If something looks wrong
| What you see | What to do |
|---|---|
| The widget renders twice in development | React strict mode mounts components twice in development only. The script skips elements it has already rendered, so production builds show one widget. |
| The widget area is blank | Check that the page is served over HTTPS and that the script tag was pasted in full. Some editors only run scripts on the published page, so check the live page rather than the editor preview. |
| The bottom of the widget is cut off | Increase the height of the embed element. The widget needs its own height plus about 40 pixels for the attribution link beneath it. |
| The colours clash with the site | Set data-fxmd-theme to light, dark or transparent to match the page background. |
Questions
Is the widget free on this platform?
Yes. Standard widgets on public pages are free while the FXMacroData attribution link stays visible. Customer-facing or subscriber-only products use the Commercial Redistribution add-on.
Do I need an API key or an account?
No. The snippet is everything the widget needs. An optional free publisher ID adds a stats page with views and clicks for your site.
How often does the data update?
The widget loads current data each time the page is opened, and the release ticker refreshes itself every two minutes. You never need to republish the page.
Can I change the currencies, language or time zone?
Yes. Each option is an attribute on the widget element. The options reference on the install guide lists every attribute and its values.