A memoized log button captures a message from an input and logs it to a display. After typing a new message and clicking Log, the old message appears instead of the new one.
Type a message and click Log — an empty entry appears in the list. Type another message and click Log again — another empty entry. The log fills with blank items instead of the typed messages.
useCallback memoizes the function and only recreates it when dependencies change. If message is not in the dependency array, the callback always closes over the initial empty string.
useCallback memoizes the function and only recreates it when dependencies change. If message is not in the dependency array, the callback always closes over the initial empty string.