Last week I talked about the state hook (useState
) for React’s functional components. This week I’ll be diving into the effect hook: useEffect
.
In the past, only class components had the capability of keeping track of state. This was an object where you can store property values that belong to the component. When the state object changes, the component re-renders. Functional components just accepted data to to display and were purely presentational. In fact, functional components used to be called “stateless components”.
This was one of my code exercises for the day (from freeCodeCamp):
Recently, I was presented with a coding exercise that required me to write a function that takes in a list of integers and n as arguments and removes the integers that appear at least n times from the given list. The list would contain no more than 99 integers, the order of the integers should not be changed, and the duplicates as well as the first occurence of the integer should be removed (for example: given [10, 15, 5, 10] and 2, the solution should output [15, 5]). We were allowed to implement the solution in either Java or Python, neither of which, at the time, I had learned.