@microsurveysai/react-native

中文文档
0.1.3发布于 2026/11/02MITTypeScriptESM + CJS零依赖

React Native SDK for MicroSurveys — native in-app surveys, triggered on-device by the events you already track.

原始使用文档
文档目录6 节
  1. Quick start
  2. Inline surveys
  3. Options
  4. Example app
  5. Development
  6. License

MicroSurveys React Native SDK

In-app micro-surveys for React Native and Expo apps, published to npm as @microsurveysai/react-native. The React Native counterpart to the MicroSurveys iOS SDK, for apps built on MicroSurveys. Surveys you publish in the dashboard are evaluated on-device against the events you already track, and presented natively as a bottom sheet or dialog. Works with Expo (including Expo Go) and bare React Native, on iOS and Android.

npx expo install @microsurveysai/react-native @react-native-async-storage/async-storage react-native-safe-area-context

Quick start

import { MicroSurveys, MicroSurveysProvider } from "@microsurveysai/react-native";

export const ms = new MicroSurveys({ apiKey: "ms_live_…" });

export default function App() {
  return (
    <MicroSurveysProvider instance={ms}>
      <RootNavigator />
    </MicroSurveysProvider>
  );
}

Then either forward your Amplitude events:

import { add } from "@amplitude/analytics-react-native";

add(ms.amplitudePlugin()); // events + identity flow in; events pass through unmodified

or track and identify manually:

ms.identify("user_123", { plan: "pro" });
ms.track("checkout_completed", { amount: 42 });

Inside components, useMicroSurveys() returns the same track / identify.

Inline surveys

import { MicroSurvey } from "@microsurveysai/react-native";

<MicroSurvey surveyId="svy_abc" onComplete={(result) => console.log(result)} />;

Options

new MicroSurveys({...})Default
apiKey—Your project API key.
apiBaseURLhttps://console.microsurveys.aiFor self-hosted deployments.
refreshOnForegroundtrueOn app foreground, retry queued ingest and refresh a stale config.
configTTLms12hHow long the cached config counts as fresh.
storageAsyncStorageA synchronous store (e.g. MMKV) to persist into instead.
appVersion—Your app's version (e.g. "3.2.0"), sent with responses so results can be compared across releases. With Expo, pass Application.nativeApplicationVersion from expo-application.

<MicroSurveysProvider> also takes autoStart (default true) and fontFamily (a font your app registered, e.g. with expo-font; surveys use the system font otherwise).

To preview a survey without a backend, render <SurveyModal survey={…} theme={…} /> directly.

Full guide: https://docs.microsurveys.ai/react-native-sdk

Example app

example/ is an Expo app that presents every question type without a backend:

cd example && npm install && npx expo start --ios

Development

npm install
npm run typecheck
npm test        # vitest
npm run build   # tsup → ESM + CJS + d.ts

Releases are published to npm and tagged here, with notes on the Releases page. This repository doesn't take pull requests; found a bug or need something? Open an issue.

License

MIT

版本与发布记录

@microsurveysai/react-native 共发布 5 个版本,首次发布于 2026/10/20;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.1.3latest2026/11/021 天前
0.1.22026/10/259 天前
0.1.12026/10/2014 天前
0.1.02026/10/2014 天前
0.0.0-stage2026/10/2014 天前

关于 @microsurveysai/react-native 的常见问题

@microsurveysai/react-native 是什么?

React Native SDK for MicroSurveys——原生应用内调查,由你已经跟踪的事件在设备上触发。

如何安装 @microsurveysai/react-native?

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

@microsurveysai/react-native 支持 TypeScript 吗?

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

@microsurveysai/react-native 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@microsurveysai/react-native 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@microsurveysai/react-native 可以商用吗?

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

@microsurveysai/react-native 还在维护吗?

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