-
Notifications
You must be signed in to change notification settings - Fork 41
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
Flush styles synchronously #72
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ | |
"release": "np --no-2fa" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=16.8" | ||
"react": ">=16.8", | ||
"react-dom": ">=16.8" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
|
@@ -52,8 +53,8 @@ | |
"@testing-library/react": "^10.0.2", | ||
"@types/jest": "^25.1.2", | ||
"@types/raf": "^3.4.0", | ||
"@types/react": "^16.9.19", | ||
"@types/react-dom": "^16.9.5", | ||
"@types/react": "^17.0.3", | ||
"@types/react-dom": "^17.0.3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These expose |
||
"@types/styled-components": "^5.0.1", | ||
"babel-loader": "^8.0.6", | ||
"cypress": "^4.2.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
import { | ||
useState, | ||
useRef, | ||
useCallback, | ||
TransitionEvent, | ||
CSSProperties, | ||
} from 'react'; | ||
import { useState, useRef, TransitionEvent, CSSProperties } from 'react'; | ||
import { flushSync } from 'react-dom'; | ||
import { | ||
noop, | ||
callAll, | ||
|
@@ -54,12 +49,20 @@ export default function useCollapse({ | |
height: collapsedHeight, | ||
overflow: 'hidden', | ||
}; | ||
const [styles, setStyles] = useState<CSSProperties>( | ||
const [styles, setStylesRaw] = useState<CSSProperties>( | ||
isExpanded ? {} : collapsedStyles | ||
); | ||
const mergeStyles = useCallback((newStyles: {}): void => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed useCallback because I don't see the point in having it here. |
||
const setStyles = (newStyles: {} | ((oldStyles: {}) => {})): void => { | ||
// We rely on reading information from layout | ||
// at arbitrary times, so ensure all style changes | ||
// happen before we might attempt to read them. | ||
flushSync(() => { | ||
setStylesRaw(newStyles); | ||
}); | ||
}; | ||
const mergeStyles = (newStyles: {}): void => { | ||
setStyles((oldStyles) => ({ ...oldStyles, ...newStyles })); | ||
}, []); | ||
}; | ||
|
||
function getTransitionStyles( | ||
height: number | string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're going to need this. Idk if this deserves a major/minor bump. Since this package technically only works with react-dom anyway.