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] => value * 0.425); const data2co2 = TotalRevenueSeries[1] => value * 0.425); const co2savings =, 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?
No description
3 Replies
sunny-green16mo ago
Hey @brunob.bueno, It seems a React question, maybe the community can help you 🙏
harsh-harlequin16mo ago
Maybe you can use a react context or store it in a store like redux
Context – React
A JavaScript library for building user interfaces
Redux - A predictable state container for JavaScript apps. | Redux
A predictable state container for JavaScript apps.
harsh-harlequin16mo ago
I think a context would be a bit easier