-
Notifications
You must be signed in to change notification settings - Fork 73
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
refactor: useEventNotStable type #2741
Conversation
Your org requires the Graphite merge queue for merging into mainAdd the label “flow:merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “flow:hotfix” to add to the merge queue as a hot fix. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Coverage report for
|
St.❔ |
Category | Percentage | Covered / Total |
---|---|---|---|
🔴 | Statements | 5.15% | 348/6760 |
🔴 | Branches | 4.69% (-0% 🔻) |
218/4649 |
🔴 | Functions | 3.01% | 67/2226 |
🔴 | Lines | 5.04% | 333/6605 |
Test suite run success
93 tests passing in 12 suites.
Report generated by 🧪jest coverage report action from 253d05e
const inputToAliasPath = useCallback( | ||
(name: VFolderKey, input?: string) => { | ||
if (_.isEmpty(input)) { | ||
if (input === undefined || input === '') { | ||
return `${aliasBasePath}${name}`; | ||
} else if (input?.startsWith('/')) { | ||
} else if (input.startsWith('/')) { | ||
return input; | ||
} else { | ||
return `${aliasBasePath}${input}`; | ||
} | ||
}, | ||
[aliasBasePath], | ||
); |
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.
I understood that the reason you used the useCallback hook is to prevent the component from declaring a function with new memory allocation when the component is re-rendered, but is it always a good idea to declare the function using useCallback even if the computation of the function is not heavy?
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.
Yes, it's not necessary in that case. But let's keep this code to distinguish that aliasBasePath
is a dependency.
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.
LGTM
Merge activity
|
This pull request includes several changes to improve type safety and optimize the performance of React components by using `useCallback` and ensuring proper type handling in hooks. The most important changes include modifications to `DynamicInputNumber`, `DynamicUnitInputNumberWithSlider`, and `VFolderTable` components, as well as updates to the `useEventNotStable` hook. ### Type Safety Improvements: * [`react/src/components/DynamicStepInputNumber.tsx`](diffhunk://#diff-b3d890e46cddb08acfce125b27ff3da0ca9db076ab3ebcd35fadace06e7c8d92L32-R32): Updated the `updateKey` call to use `value.toString()` to ensure the value is a string. * [`react/src/components/DynamicUnitInputNumberWithSlider.tsx`](diffhunk://#diff-26552acf4047ca1f6af64dbcf17ecdce04c84a7f669f055db97e13afe873a6e7L54-R54): Updated the `updateKey` call to use `value?.toString()` to handle potential undefined values safely. ### Performance Optimizations: * [`react/src/components/VFolderTable.tsx`](diffhunk://#diff-14f34a27406ff418af22058ec3978654932614d41995f8f9a6f52f92e32f47c8L247-R263): Replaced `useEventNotStable` with `useCallback` for `inputToAliasPath` to improve performance and stability. * [`react/src/hooks/useEventNotStable.tsx`](diffhunk://#diff-44cbecbfeea00712d81f6d06b52dbb0e5c7bad616c790244d4b238851e70e83dL3-R7): Enhanced the `useEventNotStable` hook to use generics for better type safety and updated the return type to `undefined` instead of `null`. [[1]](diffhunk://#diff-44cbecbfeea00712d81f6d06b52dbb0e5c7bad616c790244d4b238851e70e83dL3-R7) [[2]](diffhunk://#diff-44cbecbfeea00712d81f6d06b52dbb0e5c7bad616c790244d4b238851e70e83dL14-R19) ### Code Cleanup: * [`react/src/components/VFolderTable.tsx`](diffhunk://#diff-14f34a27406ff418af22058ec3978654932614d41995f8f9a6f52f92e32f47c8L34-R40): Added missing imports for `useCallback` to ensure the code compiles correctly.
1d7ea84
to
253d05e
Compare
This pull request includes several changes to improve type safety and optimize the performance of React components by using
useCallback
and ensuring proper type handling in hooks. The most important changes include modifications toDynamicInputNumber
,DynamicUnitInputNumberWithSlider
, andVFolderTable
components, as well as updates to theuseEventNotStable
hook.Type Safety Improvements:
react/src/components/DynamicStepInputNumber.tsx
: Updated theupdateKey
call to usevalue.toString()
to ensure the value is a string.react/src/components/DynamicUnitInputNumberWithSlider.tsx
: Updated theupdateKey
call to usevalue?.toString()
to handle potential undefined values safely.Performance Optimizations:
react/src/components/VFolderTable.tsx
: ReplaceduseEventNotStable
withuseCallback
forinputToAliasPath
to improve performance and stability.react/src/hooks/useEventNotStable.tsx
: Enhanced theuseEventNotStable
hook to use generics for better type safety and updated the return type toundefined
instead ofnull
. [1] [2]Code Cleanup:
react/src/components/VFolderTable.tsx
: Added missing imports foruseCallback
to ensure the code compiles correctly.