@carouseldeck/react-18

中文文档
1.5.4发布于 2026/11/04MITTypeScriptES Module构建来源已验证近 30 天下载 1938

@carouseldeck/react built for React 18: headless, composable carousel primitives on native scroll snap.

原始使用文档

@carouseldeck/react-18

@carouseldeck/react built for React 18, and for React 19 too. It has the same components, props and types, from the same source.

On React 18, install it in place of @carouseldeck/react and import from @carouseldeck/react-18. On React 19, @carouseldeck/react stays the package for an app on React 19 alone; install this one instead where a dependency needs to run on either. It is published at the same version as @carouseldeck/react, from 1.2.0.

How it is built

The source in packages/react/src is written for React 19, and this package does not change it. The React 19 package ships the same code it did before, at the same size. This package's build (vite.config.ts) adapts the source to run on React 18, and on React 19:

  • src/react.ts stands in for react. use reads a context through its own Provider, a context renders as its own provider on React 19 or a separate one on React 18, and useLayoutEffect is useEffect on the server, where React 18 warns about it. In development, it reports a React other than 18 or 19.

  • src/jsx-runtime.ts stands in for react/jsx-runtime. inert renders as React 18 needs it, left alone on React 19, which knows it as a boolean already. The deck's <style> elements render just before the viewport, one per deck, because neither build hoists them through React's own resource API, and its CSS is set as HTML, so neither version's server renderer escapes >.

    A consumer passing inert to a deck primitive should pass inert={true} (or inert alone), which this build renders correctly on React 18 and 19. Never inert="": React 19 treats inert as a boolean prop and an empty string as falsy, so it removes the attribute, leaving the element not inert, as on @carouseldeck/react.

  • Every component in the source is wrapped in forwardRef (src/with-ref.ts), so a ref reaches its element the way forwardRef passes it, on both versions.

The package has no react-server entry: this build does not ship React 19's server components either.

Tests

pnpm test:react-18 builds this package, then type-checks a consumer (test/consumer.tsx) with React 18's types. It then runs the React package's tests on React 18 against the build (vitest.react-18.config.ts at the repo root), with this package's own tests in test/. pnpm test:react-19 runs the same type-check with React 19's types instead, then the same tests on React 19 against the same build (vitest.react-19.config.ts), aliased to the React 19 the workspace already has for @carouseldeck/react. A test specific to one version's own quirks is excluded from the other's run, by name, in its config.

版本与发布记录

@carouseldeck/react-18 共发布 11 个版本,首次发布于 2026/10/13;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.5.4latest2026/11/045 天前
1.5.32026/10/2317 天前
1.5.22026/10/2317 天前
1.5.12026/10/2119 天前
1.5.02026/10/2020 天前
1.4.02026/10/1921 天前

关于 @carouseldeck/react-18 的常见问题

@carouseldeck/react-18 是什么?

@carouseldeck/react built for React 18: headless, composable carousel primitives on native scroll snap.

如何安装 @carouseldeck/react-18?

在项目目录运行 npm install @carouseldeck/react-18,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18 <20)、react-dom(>=18 <20)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@carouseldeck/react-18 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@carouseldeck/react-18 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@carouseldeck/react-18 可以商用吗?

@carouseldeck/react-18 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@carouseldeck/react-18 的下载量有多少?

根据 npm 官方下载统计,@carouseldeck/react-18 在 2026/10/09 – 2026/11/07 这 30 天内被下载 1,938 次,日均约 65 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@carouseldeck/react-18 还在维护吗?

最新版本 1.5.4 发布于 2026/11/04(5 天前);至今共发布 11 个版本,其中过去 12 个月发布了 11 个;首次发布于 2026/10/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。