How to use the history/lib/DOMStateStorage.saveState function in history

To help you get started, we’ve selected a few history examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phylogeny-explorer / explorer / client / src / client.js View on Github external
function onLocationChange(location) {
    // Save the page scroll position into the current location's state
    if (currentLocation.key) {
      saveState(currentLocation.key, {
        ...readState(currentLocation.key),
        scrollX: windowScrollX(),
        scrollY: windowScrollY(),
      });
    }
    currentLocation = location;
    UniversalRouter.resolve(routes, {
      path: location.pathname,
      query: location.query,
      state: location.state,
      context,
      render: render.bind(undefined, container, location), // eslint-disable-line react/jsx-no-bind, max-len
    }).catch(err => console.error(err)); // eslint-disable-line no-console
  }
github taion / scroll-behavior / modules / withStandardScroll.js View on Github external
savePositionHandle = requestAnimationFrame(() => {
        savePositionHandle = null

        const state = readState(currentKey)
        const scrollPosition = [ scrollLeft(window), scrollTop(window) ]

        // We have to directly update `DOMStateStorage`, because actually
        // updating the location could cause e.g. React Router to re-render the
        // entire page, which would lead to observably bad scroll performance.
        saveState(currentKey, { ...state, scrollPosition })
      })
    }
github taion / scroll-behavior / src / ScrollBehavior.js View on Github external
_savePosition(key, element) {
    // We have to directly update `DOMStateStorage`, because actually updating
    // the location could cause e.g. React Router to re-render the entire page,
    // which would lead to observably bad scroll performance.
    saveState(
      this._getKey(this._getCurrentLocation(), key),
      [scrollLeft(element), scrollTop(element)]
    );
  }
github catamphetamine / react-pages / source / react-router / location.js View on Github external
function set_location(location, history, method)
{
	// A little bit of a fight with `scroll-behavior` here
	const key = history.createKey()
	// Save the correct `scroll-behavior`'s scroll position
	// in this new history entry `scroll-behavior` state.
	saveState(`${SCROLL_STATE_KEY_PREFIX}${key}`, get_scroll())
	// Set the new `location` `key`
	location = history.createLocation(location, method, key)
	// Prevent `scroll-behavior` from messing
	// with scroll on this location transition
	location.scroll = false
	// Prevent `react-router` from remounting page component
	location.remount = false
	// Transition to the new location
	history.transitionTo(location)
}
github taion / scroll-behavior / test / withScroll.js View on Github external
save(location, key, value) {
    saveState(this.getStateKey(location, key), value);
  }
github catamphetamine / react-pages / source / redux / client / history store.js View on Github external
export function store_in_history(prefix, key, data)
{
	return saveState(compute_key(prefix, key), data)
}