drfrf
import React, { useState } from ‘react’;
import { Download, Loader2, AlertCircle, CheckCircle } from ‘lucide-react’;
export default function TikTokDownloader() {
const [url, setUrl] = useState(”);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(”);
const [success, setSuccess] = useState(”);
const handleDownload = async () => {
setError(”);
setSuccess(”);
if (!url.trim()) {
setError(‘Please enter a TikTok URL’);
return;
}
if (!url.includes(‘tiktok.com’)) {
setError(‘Please enter a valid TikTok URL’);
return;
}
setLoading(true);
try {
// Using a TikTok download API
const apiUrl = `https://www.tikwm.com/api/?url=${encodeURIComponent(url)}`;
const response = await fetch(apiUrl);
const data = await response.json();
if (data.code === 0 && data.data) {
// Create download link
const videoUrl = data.data.play;
const link = document.createElement(‘a’);
link.href = videoUrl;
link.download = `tiktok_video_${Date.now()}.mp4`;
link.target = ‘_blank’;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
setSuccess(‘Download started! Check your downloads folder.’);
} else {
setError(‘Could not fetch video. Please check the URL and try again.’);
}
} catch (err) {
setError(‘An error occurred. Please try again or use a different URL.’);
console.error(err);
} finally {
setLoading(false);
}
};
const handleKeyPress = (e) => {
if (e.key === ‘Enter’) {
handleDownload();
}
};
return (
TikTok Video Downloader
Paste any TikTok video URL to download
setUrl(e.target.value)}
onKeyPress={handleKeyPress}
placeholder=”Paste TikTok URL here (e.g., https://www.tiktok.com/@user/video/…)”
className=”w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-purple-500 transition-colors”
disabled={loading}
/>
{error && (
)}
{success && (
)}
How to use:
- Open TikTok and find the video you want to download
- Tap the Share button and copy the link
- Paste the link in the box above
- Click Download and save the video
Note: Please respect content creators’ rights and use downloaded videos responsibly.
);
}