UNPKG

react-hashchange

Version:

React component that notifies when browser's hash changes.

6 lines 2.49 kB
/*! * react-hashchange v0.1.0 * MIT Licensed */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.ReactHashChange=t(require("react")):e.ReactHashChange=t(e.React)}(this,function(e){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0}),n.d(t,"default",function(){return p});var i,c,u=n(2),s=n.n(u),f=function(){return window.location.hash},p=(c=i=function(e){function t(){var n,a,i;o(this,t);for(var c=arguments.length,u=Array(c),s=0;s<c;s++)u[s]=arguments[s];return n=a=r(this,e.call.apply(e,[this].concat(u))),a.state={hash:a.props.getLocationHash()},a.handleHashChange=function(){var e=a.props.getLocationHash();a.props.onChange({hash:e}),a.setState({hash:e})},i=n,r(a,i)}return a(t,e),t.prototype.componentDidMount=function(){window.addEventListener("hashchange",this.handleHashChange,!1)},t.prototype.componentWillUnmount=function(){window.removeEventListener("hashchange",this.handleHashChange,!1)},t.prototype.render=function(){var e=this.props,t=e.children,n=e.render;return n?n(this.state):t?"function"==typeof t?t(this.state):s.a.Children.only(t)(this.state):null},t}(u.Component),i.defaultProps={render:null,onChange:function(){},getLocationHash:f},c)},function(t,n){t.exports=e}])}); //# sourceMappingURL=react-hashchange.min.js.map