Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: apply transpile pipeline #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
]
]
}
23 changes: 9 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict'
var React = require('react')
var useState = React.useState
var useCallback = React.useCallback
var useLayoutEffect = React.useLayoutEffect
let { useCallback, useState, useLayoutEffect } = require('react')

function getSize(el) {
if (!el) {
Expand All @@ -19,11 +16,11 @@ function getSize(el) {
}

function useComponentSize(ref) {
var _useState = useState(getSize(ref ? ref.current : {}))
var ComponentSize = _useState[0]
var setComponentSize = _useState[1]
let [ComponentSize, setComponentSize] = useState(
getSize(ref ? ref.current : {})
)

var handleResize = useCallback(
const handleResize = useCallback(
function handleResize() {
if (ref.current) {
setComponentSize(getSize(ref.current))
Expand All @@ -33,27 +30,25 @@ function useComponentSize(ref) {
)

useLayoutEffect(
function() {
() => {
if (!ref.current) {
return
}

handleResize()

if (typeof ResizeObserver === 'function') {
var resizeObserver = new ResizeObserver(function() {
handleResize()
})
let resizeObserver = new ResizeObserver(() => handleResize())
resizeObserver.observe(ref.current)

return function() {
return () => {
resizeObserver.disconnect(ref.current)
resizeObserver = null
}
} else {
window.addEventListener('resize', handleResize)

return function() {
return () => {
window.removeEventListener('resize', handleResize)
}
}
Expand Down
Loading