Rev 5239 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react'
const jsonToParams = (data = {}) => {
if (!data) { return false } else {
const formBody = []
for (const property in data) {
const encodedKey = encodeURIComponent(property)
// @ts-ignore
const encodedValue = encodeURIComponent(data[property])
formBody.push(encodedKey + '=' + encodedValue)
}
const _formBody = formBody.join('&')
return _formBody
}
}
const useWindowSize = () => {
const [size, setSize] = React.useState([0, 0])
React.useLayoutEffect(() => {
function updateSize () {
setSize([window.innerWidth, window.innerHeight])
}
window.addEventListener('resize', updateSize)
updateSize()
return () => window.removeEventListener('resize', updateSize)
}, [])
return size
}
const debounce = (func, timeout = 300) => {
let timer
return (...args) => {
clearTimeout(timer)
timer = setTimeout(() => { func.apply(this, args) }, timeout)
}
}
const scrollToBottom = (element) => {
if (!element.current) {
return false
}
element.scrollTop = element.scrollHeight * 9
}
export {
useWindowSize,
jsonToParams,
debounce,
scrollToBottom
}