An implementation guide for React and React Native teams, with documented lessons from GeekyAnts, Vercel, Meta, Microsoft, and Shopify.
Generating text is only the beginning of an AI content feature. The harder work starts when a user wants to correct a sentence, regenerate one paragraph, undo a replacement, or continue editing while a response arrives.
Consider a product-description editor. A merchant requests a shorter introduction, then corrects a specification while the model is generating. If the application replaces the entire document when the response finishes, that correction disappears.
A reliable workflow must preserve the user’s work while making AI suggestions easy to review and apply. React and React Native can share much of this application logic, although their editing surfaces require different implementations.
Start With Two Separate Content States
The application should distinguish between the working document and an AI proposal.
The working document contains the user’s current content. The proposal contains a suggested change that has not yet been accepted.
This separation prevents a common implementation mistake:
// Fragile: every generated update can replace the user's work.
useEffect(() => {
setDocument(generatedText);
}, [generatedText]);If generatedText changes during streaming, the effect repeatedly overwrites the document.
Instead, stream into a preview. Let the user accept the result through an explicit action.
For a simple editor, the interface can expose:
- Replace: apply the suggestion to the intended content.
- Insert: add the suggestion without removing existing content.
- Discard: leave the document unchanged.
- Regenerate: request another proposal.
Microsoft documents similar replacement, insertion, regeneration, and adjustment actions in Copilot for Word on supported mobile devices. That provides a concrete product example of keeping generated alternatives under user control. Microsoft Support
Model the Document Before Choosing an Editor
A string is sufficient for a short description. A document with headings, lists, links, and independently editable sections benefits from structured storage.
A simplified application model might look like this:
type ContentBlock = {
id: string;
type: "heading" | "paragraph";
text: string;
};
type ContentDocument = {
id: string;
revision: number;
blocks: ContentBlock[];
};
type AIProposal = {
id: string;
requestId: string;
baseRevision: number;
targetBlockId: string;
replacementText: string;
};Stable block IDs identify what the model is changing. The revision identifies which document version the suggestion was based on.
For production rich text, use the editor’s supported schema or a deliberately designed application schema. The example above does not represent inline formatting, tables, or embedded media.
Lexical illustrates why structured editor state matters. Its document model is the source of truth, rather than the rendered DOM, and its serialization APIs support saving and restoring document content.
Keep generation metadata separate from ordinary text. Model identifiers, prompt-template versions, request IDs, and acceptance events belong in proposal or revision records.
Build Generation Behind an Authenticated Backend
The client should send a narrowly scoped request to an application backend:
{
"documentId": "doc_42",
"baseRevision": 12,
"targetBlockId": "intro",
"instruction": "Shorten this paragraph without changing specifications."
}The backend should authenticate the user, authorize access to the document, and load the relevant content from trusted storage.
It can then construct the model request using the selected passage and any necessary context.
This design gives the server control over which document the request addresses. A client-supplied document ID should never establish permission by itself.
Provider credentials should stay on the backend. In a React Native application, values bundled into the mobile client cannot be treated as private server secrets.
The generation service should also validate response structure and enforce output-size limits before making a proposal available for acceptance.
Stream Into a Preview Without Interrupting Typing
Streaming improves feedback, but it introduces another writer into the interface. The user and the model may be producing text simultaneously.
Use separate state for:
| State | Purpose |
|---|---|
| Working document | Current user-authored and accepted content |
| Generation request | Active request ID, target, and starting revision |
| Streaming preview | Partial output for the current request |
| Completed proposal | Final suggestion available for review |
| Save status | Whether the current document revision is persisted |
Do not treat a partial JSON response as a complete document. Buffer incomplete output or use a protocol that exposes structured generation events.
For Expo applications, the AI SDK’s quickstart demonstrates React Native streaming with useChat, a transport, and expo/fetch. Expo also documents streaming response access through its fetch implementation. Teams should follow the documentation matching their installed package versions.
Request IDs are essential. If a user starts a second generation, late events from the first request should not update the active preview.
Cancellation should improve resource use and responsiveness, while request-ID checks protect against responses that arrive after cancellation.
Check for Conflicts Before Applying a Suggestion
A proposal becomes stale when the document changes after generation starts.
For a single-user editor, rejecting proposals based on an older document revision is a conservative starting point:
type Draft = {
revision: number;
blocks: { id: string; text: string }[];
};
type Proposal = {
baseRevision: number;
targetBlockId: string;
replacementText: string;
};
type ApplyResult =
| { ok: true; draft: Draft }
| { ok: false; reason: "stale" | "missing-target" };
function applyProposal(
draft: Draft,
proposal: Proposal
): ApplyResult {
if (draft.revision !== proposal.baseRevision) {
return { ok: false, reason: "stale" };
}
if (!draft.blocks.some(b => b.id === proposal.targetBlockId)) {
return { ok: false, reason: "missing-target" };
}
return {
ok: true,
draft: {
revision: draft.revision + 1,
blocks: draft.blocks.map(block =>
block.id === proposal.targetBlockId
? { ...block, text: proposal.replacementText }
: block
),
},
};
}This is illustrative application logic, not a complete persistence layer.
When a conflict occurs, show the suggestion alongside the current content. Offer regeneration or manual copying instead of silently replacing newer work.
Whole-document revisions may reject suggestions even when an unrelated paragraph changed. Block-level versions can make conflict handling more precise. Collaborative editors require transaction-aware mapping or collaboration mechanisms that fit their editor model.
Adapt the Editing Surface for React Native
React Native’s TextInput supports controlled text through value and onChangeText. It is suitable for plain-text fields and simple multiline drafts. The official documentation notes that a supplied value forces the native input to match that value.
A basic editor can therefore keep typing independent of the AI preview:
<TextInput
multiline
value={draftText}
onChangeText={setDraftText}
accessibilityLabel="Content draft"
/>Rich-text requirements change the decision.
Lexical’s JavaScript editor attaches to a browser contenteditable element. Its React bindings should not be assumed to render directly as a native React Native editor.
Teams can evaluate native rich-text solutions or a web editor hosted in a WebView. A WebView approach needs explicit handling for bridge messages, focus, selection, keyboard behavior, accessibility, and navigation.
Test with real devices, long documents, emoji, and input-method composition. Streaming previews should not steal focus or repeatedly move the cursor.
Save Documents and Generation History Separately
A chat transcript is useful context, but the edited document needs its own persistence model.
Store the accepted content, document revision, and save timestamp independently from prompts and model responses.
The AI SDK documents message persistence, while explicitly noting that its example does not cover authorization and other production concerns. Applications must implement those responsibilities around the example.
For document saves, use an expected revision and enforce the comparison atomically on the server. A mismatch should return a conflict instead of overwriting another session’s changes.
Autosave should follow accepted edits and user typing. If partial generations need recovery, persist them as generation records rather than committed document revisions.
Preserve undo behavior too. Applying one proposal should normally create one reversible editor operation, not dozens of token-sized history entries.
How Five Companies Contribute to This Pattern
These public examples demonstrate different parts of editable AI workflows. They do not establish that all five companies use the same React Native architecture.
| Company | Documented practice | Relevant engineering lesson |
|---|---|---|
| GeekyAnts | Describes converting AI-generated React interfaces into editable Figma documents by examining React Fiber and reconstructing design structures. | Preserve meaningful structure so generated output remains editable downstream. |
| Vercel | Provides AI SDK examples for streaming React interfaces, Expo integration, and message persistence. | Treat generation transport, interface state, and storage as explicit implementation concerns. |
| Meta | Originated Lexical, which powers editing in Meta’s web products and maintains a structured document model. | Use editor transactions and document state for reliable editing. |
| Microsoft | Documents user-controlled drafting and rewriting actions in Copilot for Word. | Make acceptance, insertion, and rejection visible product actions. |
| Shopify | Documents generated product descriptions that merchants can edit and format before saving. | Embed generation inside an existing editing task and retain human review. |
GeekyAnts’ React-to-Figma engineering account concerns generated interfaces rather than prose editing. Its structural approach is a related design lesson, not evidence of a specific AI text-editor implementation. React Fiber is also an internal representation, so that extraction technique should not be treated as a stable public integration API.
Vercel and Meta provide implementation infrastructure; Microsoft and Shopify demonstrate product interactions. Shopify’s current documentation also identifies its description-generation flow as desktop-only, so it should not be presented as a mobile implementation reference.
Verify the Failure Cases Before Release
The most valuable checks target situations where content could be lost or incorrectly accepted:
- A user edits the target passage during generation.
- A cancelled request finishes after a newer request.
- The target block is deleted before acceptance.
- Autosave requests complete out of order.
- The app closes before a save succeeds.
- A proposal introduces unsupported formatting or unsafe links.
- Undo runs immediately after an AI replacement.
For browser rendering, treat generated HTML as untrusted input. React warns that passing untrusted HTML through dangerouslySetInnerHTML can introduce cross-site scripting vulnerabilities. Prefer validated editor nodes and an explicit policy for imported HTML and URLs.
Track time to an accepted draft, save failures, conflict frequency, and the amount of editing required after acceptance. Those measures reveal whether the feature helps users finish their work.
The central implementation rule is straightforward: generation produces a proposal; acceptance changes the document. Keeping that boundary explicit makes editing, recovery, and cross-platform behavior easier to reason about.





















Add Comment