Skip to content

FCE-2851: Add missing useCallbacks#482

Merged
MiloszFilimowski merged 2 commits intomainfrom
mfilimowski/fce-2851-missing-usecallbacks
Feb 24, 2026
Merged

FCE-2851: Add missing useCallbacks#482
MiloszFilimowski merged 2 commits intomainfrom
mfilimowski/fce-2851-missing-usecallbacks

Conversation

@MiloszFilimowski
Copy link
Collaborator

Description

Wrap returned functions in useCallback across 3 hooks in react-client:

  • useSandbox.tsgetSandboxPeerToken, getSandboxViewerToken, getSandboxLivestream
  • useStatistics.tsgetStatistics
  • useScreenshareManager.tsstartStreaming, setTracksMiddleware (returned), plus 3 internal helpers they depend on (getDisplayName, addTrackToFishjamClient, replaceTracks)

Motivation and Context

These functions were recreated on every render, causing unnecessary re-renders in consuming components and repeated effect executions when used as dependencies.

Documentation impact

  • Documentation update required
  • Documentation updated in another PR
  • No documentation update required

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)

@linear
Copy link

linear bot commented Feb 24, 2026

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request aims to prevent unnecessary re-renders by wrapping returned functions in useCallback across three hooks in the react-client package. The changes affect useSandbox.ts, useStatistics.ts, and useScreenshareManager.ts, wrapping their returned functions with useCallback to maintain stable function references across renders.

Changes:

  • Added useCallback wrappers to function returns in three hooks to stabilize function references
  • Updated imports to include useCallback from React
  • Specified dependency arrays for all memoized callbacks

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/react-client/src/hooks/useStatistics.ts Wrapped getStatistics in useCallback with client ref dependency
packages/react-client/src/hooks/useSandbox.ts Wrapped three sandbox API functions in useCallback with sandboxApiUrl dependency
packages/react-client/src/hooks/internal/useScreenshareManager.ts Wrapped multiple callbacks including startStreaming, replaceTracks, and setTracksMiddleware with state dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MiloszFilimowski MiloszFilimowski merged commit edbd968 into main Feb 24, 2026
2 checks passed
@MiloszFilimowski MiloszFilimowski deleted the mfilimowski/fce-2851-missing-usecallbacks branch February 24, 2026 15:18
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 this pull request may close these issues.

3 participants