Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

react-nextjs

БесплатноБез исполняемых скриптовНе проверен

Crée des composants React et pages Next.js avec Relay GraphQL dans admin-next/. Couvre fragments, queries, pages dynamiques, hooks et patterns du projet.

cap-collectifот cap-collectif★ 27 звёзд на GitHub15 установок в других каталогах

Об этом скилле

React / Next.js / Relay

Guide pour créer des composants React et pages Next.js dans admin-next/ avec les patterns du projet.

Structure du projet

admin-next/
├── pages/admin-next/           # Route back office (Pages Router)
│   ├── my-feature.tsx          # Page simple
│   └── entity/
│       ├── [entityId].tsx      # Page dynamique
│       └── [entityId]/
│           └── settings.tsx    # Sous-page
├── components/
│   ├── BackOffice/             # Composants admin
│   └── FrontOffice/            # Composants front-end
├── shared/                     # Composants réutilisables
├── hooks/                      # Custom hooks
├── mutations/                  # Mutations GraphQL
└── __generated__/              # Types Relay générés

Créer un composant avec fragment Relay

// components/BackOffice/MyFeature/MyFeatureCard.tsx
import { graphql, useFragment } from 'react-relay'
import type { MyFeatureCard_entity$key } from '@relay/MyFeatureCard_entity.graphql'
import { Card, CardContent, Text } from '@cap-collectif/ui'

const FRAGMENT = graphql`
  fragment MyFeatureCard_entity on Entity {
    id
    title
    description
    createdAt
  }
`

type Props = {
  entity: MyFeatureCard_entity$key
}

export const MyFeatureCard: React.FC<Props> = ({ entity: entityRef }) => {
  const entity = useFragment(FRAGMENT, entityRef)

  return (
    <Card>
      <CardContent primaryInfo={entity.title}>
        <Text>{entity.description}</Text>
      </CardContent>
    </Card>
  )
}

Conventions de nommage fragments

Element Pattern Exemple
Fragment ComponentName_fieldName ProposalCard_proposal
Type data FragmentName$data ProposalCard_proposal$data
Type key FragmentName$key ProposalCard_proposal$key
Variable FRAGMENT const FRAGMENT = graphql...

Fragment avec arguments

const FRAGMENT = graphql`
  fragment MyList_query on Query
  @argumentDefinitions(
    count: { type: "Int", defaultValue: 10 }
    cursor: { type: "String" }
    orderBy: { type: "[EntityOrder]" }
  )
  @refetchable(queryName: "MyListPaginationQuery") {
    entities(first: $count, after: $cursor, orderBy: $orderBy)
      @connection(key: "MyList_entities") {
      edges {
        node {
          id
          ...MyFeatureCard_entity
        }
      }
      totalCount
    }
  }
`

Composition de fragments

const FRAGMENT = graphql`
  fragment ParentComponent_data on Query {
    viewer {
      ...ChildComponent_viewer
    }
    node(id: $id) {
      ...AnotherChild_node
    }
  }
`

Créer une page Next.js

Pattern useQueryLoader (recommandé)

// pages/admin-next/my-feature.tsx
import * as React from 'react'
import { Suspense } from 'react'
import type { NextPage } from 'next'
import { graphql, useQueryLoader, usePreloadedQuery } from 'react-relay'
import type { PreloadedQuery } from 'react-relay'
import { useIntl } from 'react-intl'
import { Spinner } from '@cap-collectif/ui'
import Layout from '@components/BackOffice/Layout/Layout'
import { withPageAuthRequired } from '@utils/withPageAuthRequired'
import type { PageProps } from '@utils/types'
import type { myFeatureQuery as QueryType } from '@relay/myFeatureQuery.graphql'

// 1. Query au niveau module
export const myFeatureQuery = graphql`
  query myFeatureQuery {
    viewer {
      id
      username
      isAdmin
    }
    # ... other fields
  }
`

// 2. Props du composant inner
type ContentProps = {
  queryReference: PreloadedQuery<QueryType>
}

// 3. Composant inner avec usePreloadedQuery
const MyFeatureContent: React.FC<ContentProps> = ({ queryReference }) => {
  const query = usePreloadedQuery<QueryType>(myFeatureQuery, queryReference)
  const intl = useIntl()

  return (
    <div>
      {/* Contenu de la page */}
    </div>
  )
}

// 4. Page principale avec useQueryLoader
const MyFeaturePage: NextPage<PageProps> = ({ viewerSession }) => {
  const intl = useIntl()
  const [queryReference, loadQuery, disposeQuery] =
    useQueryLoader<QueryType>(myFeatureQuery)

  React.useEffect(() => {
    loadQuery({})
    return () => disposeQuery()
  }, [loadQuery, disposeQuery])

  return (
    <Layout navTitle={intl.formatMessage({ id: 'my-feature.title' })}>
      <Suspense fallback={<Spinner />}>
        {queryReference && (
          <MyFeatureContent queryReference={queryReference} />
        )}
      </Suspense>
    </Layout>
  )
}

// 5. Guard d'authentification
export const getServerSideProps = withPageAuthRequired

export default MyFeaturePage

Pattern useLazyLoadQuery (simplifie)

Pour les pages simples sans besoin de refetch :

import { useLazyLoadQuery } from 'react-relay'

const SimpleContent: React.FC<{ entityId: string }> = ({ entityId }) => {
  const response = useLazyLoadQuery<QueryType>(QUERY, { id: entityId })
  const entity = response.node

  if (!entity) {
    return <NotFound />
  }

  retu
Полный SKILL.md на GitHub

Установить react-nextjs в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл react-nextjs?

Crée des composants React et pages Next.js avec Relay GraphQL dans admin-next/. Couvre fragments, queries, pages dynamiques, hooks et patterns du projet.

Как установить скилл react-nextjs?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл react-nextjs запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить react-nextjs с