Remember last value in React functional components

Sometimes it can be very useful to save previous values of props (or state) in a React component. Perhaps this is easier to be imagined in a class component, but in a functional component, less so. However, we can use the useRef() React hook to achieve that quite efficiently. Less talk, more code (typescript)… const someFunctionalComponent = (p: {index: number}) => { // Keep the last positive value around. const

Continue reading