@@ -18,39 +18,141 @@ Avoid using direct HTML links (`<a href="">`, `<Link href="">`) or static URLs i
1818## External Navigation
1919
2020### Opening External URLs
21+ <Tabs >
22+ <Tab title = " With MiniKit" >
23+
24+ Use [ ` useOpenUrl() ` ] ( /mini-apps/technical-reference/minikit/hooks/useOpenUrl ) to safely open external websites in the client's in-app browser:
25+ ``` tsx components/ExternalLinks.tsx
26+ import { useOpenUrl } from ' @coinbase/onchainkit/minikit' ;
27+
28+ export default function ExternalLinks() {
29+ const openUrl = useOpenUrl ();
30+
31+ return (
32+ <div className = " external-links" >
33+ <button onClick = { () => openUrl (' https://base.org' )} >
34+ Visit Base.org
35+ </button >
36+ <button onClick = { () => openUrl (' https://twitter.com/base' )} >
37+ Follow on Twitter
38+ </button >
39+ <button onClick = { () => openUrl (' https://discord.gg/basechain' )} >
40+ Join Discord
41+ </button >
42+ </div >
43+ );
44+ }
2145
22- Use ` sdk.actions.openUrl() ` to safely open external websites in the client's in-app browser:
46+ // Incorrect: Direct HTML link
47+ // <a href="https://example.com">Visit Site</a>
48+ ```
49+ </Tab >
2350
24- ``` typescript App.tsx
25- import { sdk } from ' @@farcaster/miniapp-sdk' ;
51+ <Tab title = " Without MiniKit" >
2652
27- // Correct: Use SDK action
28- const openExternalSite = () => {
29- sdk .actions .openUrl (' https://example.com' );
30- };
53+ Use ` sdk.actions.openUrl() ` to safely open external websites in the client's in-app browser:
3154
32- // Incorrect: Direct HTML link
33- // <a href="https://example.com">Visit Site</a>
34- ```
55+ ``` typescript App.tsx
56+ import { sdk } from ' @farcaster/miniapp-sdk' ;
57+
58+ // Correct: Use SDK action
59+ const openExternalSite = () => {
60+ sdk .actions .openUrl (' https://example.com' );
61+ };
62+
63+ // Incorrect: Direct HTML link
64+ // <a href="https://example.com">Visit Site</a>
65+ ```
66+ </Tab >
67+ </Tabs >
3568
3669### Composing Casts
3770
38- Use ` sdk.actions.composeCast() ` instead of composer intent URLs:
71+ <Tabs >
72+ <Tab title = " With MiniKit" >
73+
74+ Use [ ` useComposeCast() ` ] ( /mini-apps/technical-reference/minikit/hooks/useComposeCast ) to open the native composer with prefilled content:
75+ ``` tsx components/ShareCast.tsx
76+ import { useComposeCast } from ' @coinbase/onchainkit/minikit' ;
77+
78+ export default function ShareCast() {
79+ const { composeCast } = useComposeCast ();
80+
81+ return (
82+ <button
83+ onClick = { () =>
84+ composeCast ({
85+ text: ' Check out this Mini App!' ,
86+ embeds: [window .location .href ]
87+ })
88+ }
89+ >
90+ Share This App
91+ </button >
92+ );
93+ }
94+
95+ // Incorrect: Composer intent URLs
96+ // window.open('https://farcaster.com/~/compose?text=...')
97+ ```
98+ </Tab >
3999
40- ``` typescript App.tsx
41- import { sdk } from ' @farcaster/miniapp-sdk' ;
100+ <Tab title = " Without MiniKit" >
42101
43- // Correct: Use SDK action
44- const shareContent = () => {
45- sdk .actions .composeCast ({
46- text: ' Check out this Mini App!' ,
47- embeds: [' https://yourminiapp.com' ]
48- });
49- };
102+ Use ` sdk.actions.composeCast() ` instead of composer intent URLs:
50103
51- // Incorrect: Composer intent URLs
52- // window.open('https://farcaster.com/~/compose?text=...')
53- ```
104+ ``` typescript App.tsx
105+ import { sdk } from ' @farcaster/miniapp-sdk' ;
106+
107+ // Correct: Use SDK action
108+ const shareContent = () => {
109+ sdk .actions .composeCast ({
110+ text: ' Check out this Mini App!' ,
111+ embeds: [' https://yourminiapp.com' ]
112+ });
113+ };
114+
115+ // Incorrect: Composer intent URLs
116+ // window.open('https://farcaster.com/~/compose?text=...')
117+ ```
118+ </Tab >
119+ </Tabs >
120+
121+ ### Viewing Casts
122+
123+ <Tabs >
124+ <Tab title = " With MiniKit" >
125+
126+ Use [ ` useViewCast() ` ] ( /mini-apps/technical-reference/minikit/hooks/useViewCast ) to open a specific cast by its hash:
127+ ``` tsx components/ViewCastButton.tsx
128+ import { useViewCast } from ' @coinbase/onchainkit/minikit' ;
129+
130+ export default function ViewCastButton() {
131+ const viewCast = useViewCast (' 0x1234567890abcdef1234567890abcdef12345678' );
132+
133+ return (
134+ <button onClick = { viewCast } >
135+ View Cast
136+ </button >
137+ );
138+ }
139+ ```
140+ </Tab >
141+
142+ <Tab title = " Without MiniKit" >
143+
144+ Use ` sdk.actions.viewCast() ` instead of cast intent URLs:
145+
146+ ``` typescript App.tsx
147+ import { sdk } from ' @farcaster/miniapp-sdk' ;
148+
149+ // Correct: Use SDK action
150+ const viewCast = () => {
151+ sdk .actions .viewCast (' https://farcaster.com/cast/1234567890' );
152+ };
153+ ```
154+ </Tab >
155+ </Tabs >
54156
55157## Best Practices
56158
@@ -67,7 +169,7 @@ Before implementing any navigation or linking functionality:
67169When using features that may not be supported in all clients:
68170
69171``` javascript App.tsx
70- import { sdk } from ' @@ farcaster/miniapp-sdk' ;
172+ import { sdk } from ' @farcaster/miniapp-sdk' ;
71173
72174const handleExternalLink = (url ) => {
73175 try {
@@ -88,7 +190,7 @@ Don't hardcode URLs specific to particular clients (like Warpcast URLs). Instead
88190### Navigation Buttons
89191
90192``` javascript NavigationComponent.tsx
91- import { sdk } from ' @@ farcaster/miniapp-sdk' ;
193+ import { sdk } from ' farcaster/miniapp-sdk' ;
92194
93195const NavigationComponent = () => {
94196 const handleExternalLink = () => {
@@ -118,7 +220,7 @@ const NavigationComponent = () => {
118220### Conditional Navigation
119221
120222``` javascript ConditionalNavigation.tsx
121- import { sdk } from ' @@ farcaster/miniapp-sdk' ;
223+ import { sdk } from ' farcaster/miniapp-sdk' ;
122224
123225const ConditionalNavigation = () => {
124226 const context = sdk .context ;
0 commit comments