Share variabel with different components.
I have a component with a usestate hook - const [co2TotalSaving, setCo2TotalSaving] = useState(0),
i have a function called calculateCo2 that change this co2TotalSaving that is trigged with a onclick , - function calculateCo2() {
const data1co2 = TotalRevenueSeries[0].data.map(value => value * 0.425);
const data2co2 = TotalRevenueSeries[1].data.map(value => value * 0.425);
const co2savings = data1co2.map((value, index) => value - data2co2[index]);
const TotalCo2S = co2savings.reduce((acc, value) => acc + value, 0) / 1000;
setCo2TotalSaving(Math.ceil(TotalCo2S));
;
}
I need to send this value achieved from the variabel to a another component where i ll do other calculations with that value, the 2 components are totally independent and should continue like that.. Can anyone help me? how do I do this?
i have a function called calculateCo2 that change this co2TotalSaving that is trigged with a onclick , - function calculateCo2() {
const data1co2 = TotalRevenueSeries[0].data.map(value => value * 0.425);
const data2co2 = TotalRevenueSeries[1].data.map(value => value * 0.425);
const co2savings = data1co2.map((value, index) => value - data2co2[index]);
const TotalCo2S = co2savings.reduce((acc, value) => acc + value, 0) / 1000;
setCo2TotalSaving(Math.ceil(TotalCo2S));
;
}
I need to send this value achieved from the variabel to a another component where i ll do other calculations with that value, the 2 components are totally independent and should continue like that.. Can anyone help me? how do I do this?

