Gatsby Browser APIs

APIs



Reference

onClientEntry

Called when the Gatsby browser runtime first starts.

Example

exports.onClientEntry = () => {
  console.log("We've started!")
  callAnalyticsAPI()
}

onInitialClientRender

Called when the initial render of Gatsby App is done on the client.

Example

exports.onInitialClientRender = () => {
  console.log("ReactDOM.render is executed")
}

onRouteUpdate

Called when the user changes routes

Parameters

destructured object
location {object}

A location object

action {object}

The “action” that caused the route change

Example

exports.onRouteUpdate = ({ location }) => {
  console.log('new pathname', location.pathname)
}

replaceRouterComponent

Allow a plugin to replace the router component e.g. to use a custom history version.

Parameters

destructured object
history {object}

The history instance to use in the replacement router instance


shouldUpdateScroll

Allow a plugin to decide if the “scroll” should update or not on a route change.

Parameters

destructured object
prevRouterProps {object}

The previous state of the router before the route change.

pathname {object}

The new pathname


wrapRootComponent

Allow a plugin to wrap the root component.

Parameters

destructured object
Root {object}

The “Root” component built by Gatsby.