Merge pull request #21304 from storybookjs/valentin/fix-next-js-types-in-13.2.0

Fix Next.js type references in Next.js >= 13.2.0
This commit is contained in:
Valentin Palkovic 2023-03-01 10:22:16 +01:00 committed by GitHub
commit 31c97a2138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1,7 @@
// Reference necessary since Next.js 13.2.0, because types in `next/navigation` are not exported per default, but
// type references are dynamically created during Next.js start up.
// See https://github.com/vercel/next.js/commit/cdf1d52d9aed42d01a46539886a4bda14cb77a99
// for more insights.
/// <reference types="next" />
/// <reference types="next/navigation-types/navigation" />

View File

@ -14,7 +14,7 @@ function Component() {
const segment = useSelectedLayoutSegment();
const segments = useSelectedLayoutSegments();
const searchParamsList = Array.from(searchParams.entries());
const searchParamsList = searchParams ? Array.from(searchParams.entries()) : [];
const routerActions = [
{

View File

@ -1,3 +1,4 @@
// usePathname and useSearchParams are only usable if experimental: {appDir: true} is set in next.config.js
import { useRouter, usePathname, useSearchParams } from 'next/navigation';
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
@ -7,7 +8,7 @@ function Component() {
const pathname = usePathname();
const searchParams = useSearchParams();
const searchParamsList = Array.from(searchParams.entries());
const searchParamsList = searchParams ? Array.from(searchParams.entries()) : [];
const routerActions = [
{