expo / router

[ARCHIVE]: Expo Router has moved to expo/expo -- The File-based router for universal React Native apps
https://docs.expo.dev/routing/introduction/
1.36k stars 113 forks source link

Incorrect type issue with useSearchParams #788

Closed senghuotlay closed 1 year ago

senghuotlay commented 1 year ago

Which package manager are you using? (Yarn is recommended)

yarn

Summary

I find it confusing as well, basically if i have sth like src/app/[...missing].tsx, and then src/app/product/[id].tsx in my

[id].tsx

import { Stack, useSearchParams } from "expo-router"; import { Text } from "react-native";

export const ProductScreen = () => { const searchParams = useSearchParams(); const id = searchParams?.id

return ( <>

  <Text>ProductScreen {id}</Text>
</>

); };

export default ProductScreen; i got this error

Property 'id' does not exist on type 'RouteParams<"/product/[id]"> | RouteParams<"/[...missing]"> | Record<string, string>'. Property 'id' does not exist on type 'RouteParams<"/[...missing]">'.ts(2339) and if i remove the [...missing].tsx, the typeerror goes away

Minimal reproducible example

none

EloB commented 1 year ago

@dalley8626 I think you missed the migration guide.

https://blog.expo.dev/introducing-expo-router-v2-3850fd5c3ca1

Update useSearchParams to useGlobalSearchParams or useLocalSearchParams depending on your needs.

senghuotlay commented 1 year ago

Although i use const searchParams = useLocalSearchParams();

i still got this error

Property 'id' does not exist on type 'RouteParams<"/[...missing]"> | RouteParams<"/product/[id]"> | Record<string, string>'.
  Property 'id' does not exist on type 'RouteParams<"/[...missing]">'.ts(2339)
senghuotlay commented 1 year ago

all good, my type issue