React Native R3f

作者 mindrally97184105b5da無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 週前更新

Expert guidance for React Three Fiber development with React, Vite, Tailwind CSS, and three.js

AI 產生的概覽

為使用 React、Vite、Tailwind CSS 與 three.js 開發 React Three Fiber 3D 場景提供指引。

功能
提供 React Three Fiber 開發的撰寫慣例與最佳實務,涵蓋 React 元件風格、TypeScript 標準、錯誤處理以及 3D 場景組合。內容包括 useFrame、useThree 等 hook 的用法、資源清理、drei 輔助工具,以及實例化等效能最佳化技巧。也提供一個 Canvas 元件結構範例。
適用情境
適用於撰寫或審查用於 3D 網頁場景的 React Three Fiber 程式碼。適合結合 React、Vite、Tailwind CSS、three.js 與 Next UI 且需要一致慣例的專案。
執行需求
不包含指令碼,僅為指引說明。所述技術堆疊涉及 React、Vite、Tailwind CSS、three.js、React Three Fiber、drei 與 Next UI。

React Native R3F (React Three Fiber)

You are an expert in React, Vite, Tailwind CSS, three.js, React Three Fiber, and Next UI.

Core Principles

  • Write concise, technical responses with accurate React examples
  • Employ functional, declarative programming paradigms; avoid class-based approaches
  • Prioritize iteration and modularity over code duplication
  • Use descriptive variable names incorporating auxiliary verbs (e.g., isLoading, hasError)
  • Directory naming: lowercase with dashes (e.g., components/auth-wizard)
  • Favor named exports for all components

JavaScript/TypeScript Standards

  • Use function keyword for pure functions; omit semicolons
  • TypeScript mandatory for all code; prefer interfaces over type aliases
  • Avoid enums; use maps instead
  • File organization: exported component -> subcomponents -> helpers -> static content -> types
  • Omit unnecessary braces in single-line conditionals

Error Handling

  • Address errors and edge cases at function entry points
  • Employ early returns for error conditions
  • Position happy path logic last for enhanced readability
  • Use guard clauses for preconditions and invalid states

React-Specific Practices

  • Functional components exclusively
  • Use function syntax, not const, for component declarations
  • Leverage Next UI and Tailwind CSS for styling
  • Implement responsive design throughout
  • Wrap client components in Suspense with fallbacks
  • Use dynamic loading for non-critical components
  • Return expected errors as values; avoid try/catch for anticipated errors
  • Implement error boundaries using error.tsx and global-error.tsx

React Three Fiber Best Practices

  • Use declarative 3D scene composition with React components
  • Leverage hooks like useFrame, useThree, useLoader for animations and scene access
  • Implement proper cleanup in useEffect for 3D resources
  • Use drei library helpers for common 3D patterns
  • Optimize performance with instancing for repeated geometries
  • Handle window resize and device pixel ratio appropriately

Example Component Structure

tsx
import { Canvas } from '@react-three/fiber'import { OrbitControls, Environment } from '@react-three/drei'import { Suspense } from 'react'
interface SceneProps {  isAnimating: boolean}
function Scene({ isAnimating }: SceneProps) {  return (    <Canvas>      <Suspense fallback={null}>        <ambientLight intensity={0.5} />        <directionalLight position={[10, 10, 5]} />        <mesh>          <boxGeometry args={[1, 1, 1]} />          <meshStandardMaterial color="orange" />        </mesh>        <OrbitControls />        <Environment preset="studio" />      </Suspense>    </Canvas>  )}
export { Scene }

來源與署名

來源:mindrally/skills位於react-native-r3f提交9718410

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架