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

feat: Add useLive() #2287

Merged
merged 1 commit into from
Nov 19, 2022
Merged

feat: Add useLive() #2287

merged 1 commit into from
Nov 19, 2022

Conversation

ntucker
Copy link
Collaborator

@ntucker ntucker commented Nov 19, 2022

Motivation

Specialization: It's fairly common to want polling when also getting the data.

Solution

Add new hook useLive() so the behaviors can still be separated if needed.

Async rendering of changing remote data.

useSuspense() + useSubscription() in one hook.

import { useLive } from '@data-client/react';
import { getTicker } from './Ticker';

function AssetPrice({ productId }: Props) {
  const ticker = useLive(getTicker, { productId });
  return (
    <center>
      {productId}{' '}
      <Formatted value={ticker.price} formatter="currency" />
    </center>
  );
}

@codecov-commenter
Copy link

Codecov Report

Merging #2287 (566f5e1) into master (ab5f7ef) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2287   +/-   ##
=======================================
  Coverage   98.30%   98.31%           
=======================================
  Files         124      125    +1     
  Lines        1950     1955    +5     
  Branches      293      293           
=======================================
+ Hits         1917     1922    +5     
  Misses         16       16           
  Partials       17       17           
Impacted Files Coverage Δ
packages/react/src/hooks/useLive.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ntucker ntucker merged commit e1623f9 into master Nov 19, 2022
@ntucker ntucker deleted the feat/uselive branch November 19, 2022 03:07
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.

None yet

3 participants