Understanding Side Effects
Side effects are actions or processes that occur in addition to another "main process". At least, this is a concise definition that helps with understanding side effects in the context of a React app.
Note
You can also look up a more scientific definition here: https://en.wikipedia.org/wiki/Side_effect_(computer_science).
In the case of a React component, the main process would be the component render cycle in which the main task of a component is to render the user interface that is defined in the component function (the returned JSX code). The React component should return the final JSX code, which is then translated into DOM-manipulating instructions.
For this, React considers state changes as the trigger for updating the user interface. Registering event handlers such as onClick
, adding refs, or rendering child components (possibly by using props) would be other elements that belong to this main process—because all...