@gmana/react-go-top
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,2 +0,2 @@ | ||
import React, { useState } from 'react'; | ||
import React, { useState, useEffect } from 'react'; | ||
@@ -11,18 +11,26 @@ var GoTop = function GoTop(_a) { | ||
var checkScrollTop = function checkScrollTop() { | ||
if (!show && window.pageYOffset > startShow) { | ||
setShow(true); | ||
} else if (show && window.pageYOffset <= startShow) { | ||
setShow(false); | ||
} | ||
}; | ||
useEffect(function () { | ||
var checkScrollTop = function checkScrollTop() { | ||
if (!show && window.pageYOffset > startShow) { | ||
setShow(true); | ||
} else if (show && window.pageYOffset <= startShow) { | ||
setShow(false); | ||
} | ||
}; | ||
window.addEventListener('scroll', checkScrollTop); | ||
return function cleanup() { | ||
window.removeEventListener('scroll', checkScrollTop); | ||
}; | ||
}, [show, startShow]); | ||
var scrollTop = function scrollTop() { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth' | ||
}); | ||
if (typeof window !== "undefined") { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth' | ||
}); | ||
} | ||
}; | ||
window.addEventListener('scroll', checkScrollTop); | ||
return show && React.createElement("div", { | ||
@@ -29,0 +37,0 @@ className: 'gmana-go-top', |
@@ -17,18 +17,26 @@ (function (global, factory) { | ||
var checkScrollTop = function checkScrollTop() { | ||
if (!show && window.pageYOffset > startShow) { | ||
setShow(true); | ||
} else if (show && window.pageYOffset <= startShow) { | ||
setShow(false); | ||
} | ||
}; | ||
React.useEffect(function () { | ||
var checkScrollTop = function checkScrollTop() { | ||
if (!show && window.pageYOffset > startShow) { | ||
setShow(true); | ||
} else if (show && window.pageYOffset <= startShow) { | ||
setShow(false); | ||
} | ||
}; | ||
window.addEventListener('scroll', checkScrollTop); | ||
return function cleanup() { | ||
window.removeEventListener('scroll', checkScrollTop); | ||
}; | ||
}, [show, startShow]); | ||
var scrollTop = function scrollTop() { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth' | ||
}); | ||
if (typeof window !== "undefined") { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth' | ||
}); | ||
} | ||
}; | ||
window.addEventListener('scroll', checkScrollTop); | ||
return show && React__default.createElement("div", { | ||
@@ -35,0 +43,0 @@ className: 'gmana-go-top', |
{ | ||
"name": "@gmana/react-go-top", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Sun Sreng", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5589
182