carbon-footprint-widget
A JavaScript library for calculating carbon footprint values.
Installation
You can install the carbon-footprint-widget
library using npm. Open your terminal or command prompt and run the following command:
npm install carbon-footprint-widget
Usage
index.js
or index.tsx
In Import the necessary components in your JavaScript or TypeScript file:
import React from "react";
import ReactDOM from "react-dom";
import { CarbonWidgetProvider } from "carbon-footprint-widget";
import App from "./App/App";
import { WIDGET_API_KEY } from "./generated/from-web/constants";
ReactDOM.render(
<React.StrictMode>
<CarbonWidgetProvider apiKey={WIDGET_API_KEY}>
<App />
</CarbonWidgetProvider>
</React.StrictMode>,
document.getElementById("root")
);
Make sure to replace WIDGET_API_KEY
with your actual API key.
Add Hooks and Component
Import the required components and hooks into your React component:
import React from "react";
import { Widget, useOffsetDeduction } from "carbon-footprint-widget";
const Cart: React.FC = () => {
// Use the useOffsetDeduction hook to get relevant information
const {
isWidgetToggleOn,
deductionAmount,
} = useOffsetDeduction();
return (
<div>
{/* Render the Widget component with the desired amount */}
<Widget amount={Number(totalPrice)} />
</div>
);
};
Ensure that you have the necessary dependencies installed, and replace totalPrice
with the actual value you want to calculate the carbon footprint for TAP.
Feel free to include any additional information, configuration options, or explanations as needed.