text: "use strict";
  
  exports.__esModule = true;
  exports.useScrollRestoration = useScrollRestoration;
  
  var _scrollHandler = require("./scroll-handler");
  
  var _react = require("react");
  
  var _reachRouter = require("@gatsbyjs/reach-router");
  
  function useScrollRestoration(identifier) {
    var location = (0, _reachRouter.useLocation)();
    var state = (0, _react.useContext)(_scrollHandler.ScrollContext);
    var ref = (0, _react.useRef)();
    (0, _react.useLayoutEffect)(function () {
      if (ref.current) {
        var position = state.read(location, identifier);
        ref.current.scrollTo(0, position || 0);
      }
    }, []);
    return {
      ref: ref,
      onScroll: function onScroll() {
        if (ref.current) {
          state.save(location, identifier, ref.current.scrollTop);
        }
      }
    };
  }