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

hooks: useMemoWithPrevious #2819

Closed
yomybaby opened this issue Nov 6, 2024 · 0 comments · Fixed by #2820
Closed

hooks: useMemoWithPrevious #2819

yomybaby opened this issue Nov 6, 2024 · 0 comments · Fixed by #2820
Assignees

Comments

@yomybaby
Copy link
Member

yomybaby commented Nov 6, 2024

Sometimes, when using useMemo, you may need to utilize the previous value. To achieve this, let's implement a custom hook that memoizes not only the value of useMemo but also the previous value when the dependency list is updated.

@yomybaby yomybaby self-assigned this Nov 6, 2024
yomybaby added a commit that referenced this issue Nov 8, 2024
Resolves #2819

**Changes:**
Introduces a new `useMemoWithPrevious` hook to manage previous and current values with reset capability, replacing the manual `useRef` implementation in ContainerLogModal. This hook provides a more robust way to track state changes while maintaining previous values.

**Implementation Details:**
- Created new `useMemoWithPrevious` hook that returns both current and previous values along with a reset function
- Updated ContainerLogModal to use the new hook for tracking log line numbers
- Replaced manual `previousLastLineNumber` ref management with the new hook's `resetPrevious` functionality
- Improved state management when switching kernel IDs or changing log sizes

**Testing Requirements:**
- Verify log highlighting works correctly when switching between different kernels
- Confirm previous line numbers are properly reset when changing log sizes
- Check that log display maintains proper highlighting of new content
@yomybaby yomybaby closed this as completed Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant