DEV Community

Taha Majlesi Pour
Taha Majlesi Pour

Posted on

Build Your First AI App with React + Tailwind โ€” Even If You're a Beginner!

๐ŸŽฏ Goal: Help beginners build a simple, working AI app using React, Tailwind CSS, and a free AI API (like OpenAI or HuggingFace).

๐Ÿง  No heavy theory. No complex code. Just easy steps with real results.


๐ŸŒŸ Why You Should Read This

  • โœ… You're curious about AI but donโ€™t know where to start
  • โœ… You want a hands-on project to show off or use
  • โœ… You like pretty UIs (Tailwind โค๏ธ)
  • โœ… You want that โ€œI built this myselfโ€ feeling!

๐Ÿงฐ What You'll Use

  • React (with Vite for speed)
  • Tailwind CSS for styling
  • Free AI API (OpenAI or HuggingFace)
  • Fetch API for making requests

๐Ÿš€ Letโ€™s Get Started

๐ŸŽจ Set Up Your Project

npm create vite@latest ai-react-app --template react cd ai-react-app npm install npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p 
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”ง Configure Tailwind

Replace the content of your tailwind.config.js with:

/** @type {import('tailwindcss').Config} */ export default { content: [ "./index.html", "./src/**/*.{js,ts,jsx,tsx}", ], theme: { extend: {}, }, plugins: [], } 
Enter fullscreen mode Exit fullscreen mode

Update your src/index.css:

@tailwind base; @tailwind components; @tailwind utilities; 
Enter fullscreen mode Exit fullscreen mode

And include it in your main.jsx:

import React from 'react' import ReactDOM from 'react-dom/client' import App from './App.jsx' import './index.css' ReactDOM.createRoot(document.getElementById('root')).render( <React.StrictMode> <App /> </React.StrictMode> ) 
Enter fullscreen mode Exit fullscreen mode

๐Ÿง  Create a Simple AI App

Letโ€™s build a small text generator using OpenAI or HuggingFaceโ€™s free API.

๐Ÿ—‚๏ธ Create Your App.jsx File :

import { useState } from "react"; function App() { const [input, setInput] = useState(""); const [response, setResponse] = useState(""); const [loading, setLoading] = useState(false); const handleGenerate = async () => { if (!input.trim()) return; setLoading(true); try { const res = await fetch("https://api-inference.huggingface.co/models/gpt2", { method: "POST", headers: { "Authorization": "Bearer YOUR_HUGGINGFACE_API_KEY", "Content-Type": "application/json" }, body: JSON.stringify({ inputs: input }) }); const data = await res.json(); setResponse(data?.[0]?.generated_text || "No response ๐Ÿ˜ฅ"); } catch (err) { setResponse("Something went wrong ๐Ÿ˜ต"); } finally { setLoading(false); } }; return ( <div className="min-h-screen bg-gray-900 text-white p-8 flex flex-col items-center justify-center"> <h1 className="text-3xl font-bold mb-6 text-center">๐Ÿค– Tiny AI Generator</h1> <textarea className="w-full max-w-md p-4 rounded bg-gray-800 mb-4" rows="5" placeholder="Type a sentence to continue..." value={input} onChange={(e) => setInput(e.target.value)} /> <button onClick={handleGenerate} className="bg-blue-500 hover:bg-blue-600 text-white px-6 py-2 rounded disabled:opacity-50" disabled={loading} > {loading ? "Generating..." : "Generate with AI"} </button> {response && ( <div className="mt-6 bg-gray-800 p-4 rounded max-w-md w-full"> <p className="text-green-400 font-semibold">AI Says:</p> <p>{response}</p> </div> )} </div> ); } export default App; 
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”‘ Get Your API Key

1. Go to Hugging Face

2. Sign up or log in

3. Go to Settings โ†’ Access Tokens โ†’ Create a new token

4. Replace "YOUR_HUGGINGFACE_API_KEY" with your token

๐ŸŽ‰ Done! Youโ€™ve Built an AI App!

You just:

  • ๐ŸŽจ Set up a styled React app
  • ๐Ÿ”— Connected to a real AI API
  • โšก Built an app that does something cool

Take a second and appreciate it โ€” youโ€™re leveling up as a dev ๐Ÿ’ช

๐Ÿ’ก Bonus Ideas

Want to take it further?

  • Let users choose tone or length
  • Add history of responses
  • Deploy it on Vercel or Netlify
  • Use OpenAIโ€™s GPT-3.5 API for better results

๐Ÿ”ฅ Final Thoughts

AI isnโ€™t just for experts. Youโ€™ve already done more than most people just by building and experimenting.

Start small, stay curious, and keep shipping ๐Ÿš€

๐Ÿ‘‹ Like This? Letโ€™s Connect!

  • ๐Ÿ”— Instagram: @tahamjp
  • ๐Ÿ“š Check out more: My Other Dev Articles

๐Ÿ’ฌ Leave a comment below if you got stuck or want help!


๐Ÿง‘โ€๐Ÿ’ป Written by Taha Majlesi

Top comments (1)

Collapse
 
tahamjp profile image
Taha Majlesi Pour

๐Ÿ™Œ Thanks for reading! Follow me for more front-end tips ๐Ÿ’ก