This is how javascript closure works.
Your useEffect runs only once ([] dependency array). And the function inside addEventListener is a closure and captures the state when useEffect runs. Since offsets is initialized as null (or its initial state), this function always logs the initial state, eventhough when the component re-renders and offsets changes.Because of the ([] dependency array).