
Research
PyPI Package Disguised as Instagram Growth Tool Harvests User Credentials
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
predictive-textarea
Advanced tools
A rich text input with AI-powered autocomplete content predictions for React
A textarea component with AI-powered content prediction for React applications. It enables predictive text suggestions as users type, similar to GitHub Copilot's ghost text feature.
You can see a demo of the component here which includes options to test different variations of the component.
npm install predictive-textarea
# or
yarn add predictive-textarea
# or
pnpm add predictive-textarea
The component has minimal dependencies:
To run the demo locally:
# Install dependencies
yarn install
# Run the demo
yarn demo
The demo shows different examples of the PredictiveTextarea component:
Press Tab to accept suggestions when they appear.
This project provides two environments for development:
Run the development server for local development:
# Start the development server (Vite)
yarn dev
The development server is located in the dev/
directory and provides a sandbox environment for testing and developing the component.
Run the demo application to see the component in action in various scenarios:
# Run the Next.js demo
yarn demo
The demo is located in the demo/
directory and showcases different usage examples of the component in a Next.js application.
import React from 'react';
import { PredictiveTextarea } from 'predictive-textarea';
// Your content prediction function
// This should connect to your AI service that generates predictions and return a string
async function getContentPrediction(text: string): Promise<string> {
const response = await fetch('your-prediction-api-endpoint', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text }),
});
const data = await response.json();
return data.prediction || '';
}
function MyForm() {
return (
<div className="my-form">
<label htmlFor="content">Content:</label>
<PredictiveTextarea
name="content"
getContentPredictionFn={getContentPrediction}
debounceTime={300}
placeholder="Start typing..."
/>
<button type="submit">Submit</button>
</div>
);
}
export default MyForm;
This package includes built-in OpenAI integration for text predictions.
To use the OpenAI integration in a Next.js app:
// app/actions.ts
'use server'
import { predictInputContent } from 'predictive-textarea/openai'
export async function getPrediction(text: string) {
return predictInputContent(text)
}
// app/components/my-textarea.tsx
'use client'
import { PredictiveTextarea } from 'predictive-textarea'
import { getPrediction } from '../actions'
export function MyTextarea() {
return <PredictiveTextarea getContentPredictionFn={getPrediction} />
}
In order to use the OpenAI integration, you need to set the OPENAI_API_KEY
environment variable in your Next.js application.
The OPENAI_MODEL
environment variable is optional and defaults to gpt-4o-mini
.
Name | Type | Required | Description |
---|---|---|---|
getContentPredictionFn | (text: string, abortSignal?: AbortSignal) => string | Promise<string> | Yes | Function that returns prediction text based on user input |
debounceTime | number | No | Time to wait after typing stops before fetching predictions (ms) |
disabled | boolean | No | Disables the textarea |
placeholder | string | No | Placeholder text |
value | string | No | Initial value |
rows | number | No | Number of rows to display (default: 1) |
className | string | No | Additional CSS classes for the textarea container |
predictionClassName | string | No | Additional CSS classes for the prediction text |
...props | React.HTMLAttributes<HTMLDivElement> | No | Any other props are passed to the underlying div |
The component uses utility classes that are compatible with Tailwind CSS by default.
To customize the appearance, you can provide a className
prop:
<PredictiveTextarea
getContentPredictionFn={getContentPrediction}
className="min-h-[200px] font-mono bg-gray-100 dark:bg-gray-800"
/>
This component is designed to be framework-agnostic and can be integrated with any UI library. The component uses Tailwind CSS conventions that make it easy to customize:
The PredictiveTextarea component includes built-in caching and performance optimization features to minimize API calls and improve user experience.
The component uses a trie-based caching mechanism to store and retrieve predictions:
// Example showing caching behavior
function MyForm() {
// This function will only be called once for the same input
// even if the component re-renders
async function getContentPrediction(text: string) {
console.log('Making API call for:', text);
// Your prediction API call here
return 'predicted text';
}
return (
<PredictiveTextarea
getContentPredictionFn={getContentPrediction}
debounceTime={300} // Configure debounce time
/>
);
}
To prevent excessive API calls as users type:
debounceTime
prop to match your use case+import React from 'react';
+import { PredictiveTextarea } from 'predictive-textarea';
+
function MyComponent() {
return (
<PredictiveTextarea
getContentPredictionFn={getContentPrediction}
debounceTime={500} // Increase to 500ms for slower typing or expensive API calls
/>
);
}
The caching and debouncing mechanisms provide several performance benefits:
While the cache is configured with sensible defaults, you can customize its behavior by adjusting the debounceTime
prop:
This component was inspired by and adapted from react-ghost-text.
FAQs
A rich text input with AI-powered autocomplete content predictions for React
We found that predictive-textarea demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.