-
Notifications
You must be signed in to change notification settings - Fork 734
DialogDismissibleView - refactor to function #1170
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
Conversation
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.
@M-i-k-e-l
I think there's is a misusage of the useCallback hook.
I wrote a few comments, but overall I think it most cases you don't to use useCallback
The main purpose for using it for a function is when you want to pass a callback as a prop for another component.
And since here it's not the case, most function can just be a regular functions.
const prevSwipeDirections = useRef<PanDirectionsProps>(); | ||
const visible = useRef<boolean>(Boolean(propsVisible)); | ||
|
||
const getHiddenLocation = useCallback((left: number, top: number): LocationProps => { |
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.
Why are you using useCallback
here? You're not passing it as a prop
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.
But it's being used in onLayout
which is passed as a prop.
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.
Then I think it's enough that only onLayout will be wrapped with useCallback, no?
getHiddenLocation
can be a pure function that has no dependencies
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.
Are we leaving this as is (following our meeting today)?
private thresholdX = 0; | ||
private thresholdY = 0; | ||
private ref = React.createRef<any>(); | ||
const animateTo = useCallback((toValue: number, animationEndCallback?: Animated.EndCallback) => { |
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.
No need for useCallback
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.
Used in onLayout
as well.
|
||
constructor(props: Props) { | ||
super(props); | ||
const isSwiping = useCallback((): boolean => { |
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.
Also here.. useCallback seem redundant.
Even the function content only use reference values
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.
Also, verify you really need to declare a return type.
Typescript usually handles it automaticaly
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.
isSwiping
is used in onDrag
which is used in useEffect
.
Removed a couple of return values.
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.
Approved.
There's is a conflict needed to resolve
Description
DialogDismissibleView - refactor to function
Changelog
DialogDismissibleView - refactor to function