-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: suspense support for usePublication hook
- Loading branch information
Showing
6 changed files
with
124 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@lens-protocol/react": minor | ||
"@lens-protocol/react-native": minor | ||
"@lens-protocol/react-web": minor | ||
--- | ||
|
||
**feat:** experimental React Suspense support in `usePublication` hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,42 @@ | ||
import { publicationId, usePublication } from '@lens-protocol/react-web'; | ||
import { Suspense, startTransition, useState } from 'react'; | ||
|
||
import { PublicationCard } from '../components/cards'; | ||
import { ErrorMessage } from '../components/error/ErrorMessage'; | ||
import { Loading } from '../components/loading/Loading'; | ||
|
||
export function UsePublication() { | ||
const { | ||
data: publication, | ||
error, | ||
loading, | ||
} = usePublication({ forId: publicationId('0x56-0x02') }); | ||
function UsePublicationInner({ id }: { id: string }) { | ||
const { data, error } = usePublication({ forId: publicationId(id), suspense: true }); | ||
|
||
if (error) { | ||
return <p>Publication not found.</p>; | ||
} | ||
|
||
if (loading) return <Loading />; | ||
return <PublicationCard publication={data} />; | ||
} | ||
|
||
if (error) return <ErrorMessage error={error} />; | ||
export function UsePublication() { | ||
const [id, setId] = useState('0x36-0x3f'); | ||
|
||
const update = (event: React.ChangeEvent<HTMLInputElement>) => | ||
startTransition(() => { | ||
if (event.target.value.length > 0) { | ||
setId(event.target.value); | ||
} | ||
}); | ||
|
||
return ( | ||
<div> | ||
<h1> | ||
<code>usePublication</code> | ||
</h1> | ||
<PublicationCard publication={publication} /> | ||
|
||
<label> | ||
Publication ID <input type="text" name="localName" defaultValue={id} onChange={update} /> | ||
</label> | ||
|
||
<Suspense fallback={<Loading />}> | ||
<UsePublicationInner id={id} /> | ||
</Suspense> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters