React "use" and Typescript
Answered
Masai Lion posted this in #help-forum
Masai LionOP
How to use this https://nextjs.org/docs/messages/sync-dynamic-apis#possible-ways-to-fix-it
with typescript?
TS2345: Argument of type { theme?: string | undefined; } is not assignable to parameter of type Usable<unknown>
with typescript?
type AppProps = {
searchParams: {
theme?: z.infer<typeof Theme>
}
}
export default function App({ searchParams }: AppProps) {
const { theme } = React.use(searchParams)
...TS2345: Argument of type { theme?: string | undefined; } is not assignable to parameter of type Usable<unknown>
Answered by joulev
type AppProps = {
searchParams: Promise<{
theme?: z.infer<typeof Theme>
}>
}2 Replies
@Masai Lion How to use this https://nextjs.org/docs/messages/sync-dynamic-apis#possible-ways-to-fix-it
with typescript?
tsx
type AppProps = {
searchParams: {
theme?: z.infer<typeof Theme>
}
}
export default function App({ searchParams }: AppProps) {
const { theme } = React.use(searchParams)
...
TS2345: Argument of type { theme?: string | undefined; } is not assignable to parameter of type Usable<unknown>
type AppProps = {
searchParams: Promise<{
theme?: z.infer<typeof Theme>
}>
}Answer