'JS - Solidity: Events vs View Functions to retrieve data

I have a JavaScript/React FrontEnd where I want to retrieve and show variables that have been stored in my Solidity Smart Contract. I know that I can emit an event each time I need to retrieve those variables and read from my JS app, however emit and store events will cost gas. Why cannot simply continuous polling a GetData view function (using setInterval), where for example I recall data from my js app every 2 seconds? As view functions cost no gas, why it is preferred to use events to store and retrieve data?



Solution 1:[1]

Events are like notifications about the state changes in smart contract and are usually used in corresponding state changing functions. Events also cost less gas than a function call. Take a look at this question. Furthermore, Events are cheaper as compared to storing data in the contract. You can read more about it here.

Also, view functions do cost gas if they are called from a transaction that results in state change of the contract

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Taimoor