Next.js Discord

Discord Forum

React "use" and Typescript

Answered
Masai Lion posted this in #help-forum
Open in Discord
Masai LionOP
How to use this https://nextjs.org/docs/messages/sync-dynamic-apis#possible-ways-to-fix-it

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>
    }>
}
View full answer

2 Replies