Mod 9 Flashcards
If we want to execute some functionality when a React component is first mounted, which hook should we use?
useEffect
Can we run multiple Express servers, e.g., the one hosting a REST API and another hosting a development React app, on the same port on the same machine?
Hell no, you need different ports (ex: 3000 for Rest API and 8000 for React app)
What is a common technique to share state between different components that are not in an ancestor-descendant relationship?
Define the state to be shared in a common ancestor of the components and pass it down to the components that need to share it.
What are the three stages in the lifecycle of a React component?
Mounting: initial Display
Updating: when setState() is called
Unmounting: When component is being removed
Consider the case when a page is first displayed and we want to display data in the page by calling a REST endpoint. When should we call the REST API and why?
We should call the REST API during the mounting stage since we want to display the data when the page is first displayed (this is when mounting occurs).