Next.js 14/15 和 React Extension Snippets 由 RED Group 和 htmllessons 共同推出,旨在为开发者提供高效的代码片段,帮助您在 Next.js 14/15 (app) 目录中快速开发。无论您是使用 TypeScript 还是 JavaScript,这些片段都能大幅提升您的开发效率。
使用方法:
这些代码片段支持 Tab 触发,可以在 TypeScript React、JavaScript React 以及部分 JavaScript、TypeScript 环境中使用。
主要代码片段:
接口创建
interface Props {
${1}
}
控制台日志
console.log(${1})
Next 14/15 | 页面 SEO 组件
import type { Metadata } from 'next'
export const metadata: Metadata = { title: '${1}', description: '${2}' }
export default function ${3}Page() { return
Next 14/15 | 页面不索引组件
import type { Metadata } from 'next'
import { NO_INDEX_PAGE } from '@/constants/seo.constants'
export const metadata: Metadata = { title: '${1}', ...NO_INDEX_PAGE // { robots: { index: false, follow: false } } }
export default function ${2}Page() { return
Next 14/15 | 布局组件
import type { PropsWithChildren } from 'react'
export default function Layout({ children }: PropsWithChildren
Next 14/15 | 客户端组件
'use client'
interface Props {}
export function ${TM_FILENAME_BASE}({}: Props) { return
Next 14/15 & React | 简单组件
export function ${TM_FILENAME_BASE}() {
return ${TM_FILENAME_BASE}
}
Next 14/15 & React | 带接口的简单组件
interface Props {}
export function ${TM_FILENAME_BASE}({}: Props) { return
Next 14/15 | 生成元数据
import type { Metadata } from 'next'
export async function generateMetadata({
params,
}: {
params: { ${slug} }
}): Promise
Next 14/15 | 元数据
import type { Metadata } from 'next'
export const metadata: Metadata = { title: '${1}', description: '${2}' }
Next 14/15 | 为动态页面生成静态参数
触发词: gsp
描述: Next 14/15 | 为动态页面生成静态参数。
export async function generateStaticParams() {
const posts = await fetch('${fetch url}').then(res => res.json())
return posts.map(post => ({
slug: post.slug
}))
}
钩子创建
export function ${TM_FILENAME_BASE}() {
${1}
return {}
}
导入样式模块
import styles from './${1}${TM_FILENAME_BASE}.module.scss'
导入 clsx 作为 cn
import cn from 'clsx'
从 framer-motion 导入 m
import { m } from 'framer-motion'
调用 useAuth 钩子
const {${1}} = useAuth()
祝您编程愉快且高效!同时,来自 RED Group 的祝福,祝您有一个高效的一天!?
本站所有资源都是由网友投稿发布,或转载各大下载站, 请自行检测软件的完整性!
本站所有资源仅供学习与参考,请勿用于商业用途,否则 产生的一切后果将由您自己承担!
如有侵权请联系我们删除下架,联系方式:study_golang@163.com