Author: saqibkhan

  • Chat Application

    Step 1: Set Up Your React Project

    Open your terminal and run the following commands:

    npx create-react-app chat-app
    cd chat-app
    

    Step 2: Create Chat Application Components

    Replace the content of src/App.js with the following code:

    import React, { useState } from 'react';
    import './App.css';
    
    const App = () => {
      const [messages, setMessages] = useState([]);
      const [message, setMessage] = useState('');
      const [username, setUsername] = useState('');
    
      const handleSendMessage = () => {
    
    if (message && username) {
      setMessages([...messages, { username, text: message }]);
      setMessage('');
    }
    }; return (
    <div className="App">
      <h1>Chat Application</h1>
      <div className="chat-window">
        <div className="messages">
          {messages.map((msg, index) => (
            <div key={index} className="message">
              <strong>{msg.username}: </strong>
              {msg.text}
            </div>
          ))}
        </div>
      </div>
      <input
        type="text"
        placeholder="Your name"
        value={username}
        onChange={(e) => setUsername(e.target.value)}
      />
      <input
        type="text"
        placeholder="Type a message"
        value={message}
        onChange={(e) => setMessage(e.target.value)}
      />
      <button onClick={handleSendMessage}>Send</button>
    </div>
    ); }; export default App;

    Step 3: Style Your Chat Application

    Open src/App.css and add the following styles:

    body {
      margin: 0;
      font-family: Arial, sans-serif;
    }
    
    .App {
      text-align: center;
      padding: 20px;
    }
    
    .chat-window {
      border: 1px solid #ccc;
      padding: 10px;
      height: 300px;
      overflow-y: scroll;
      margin-bottom: 20px;
    }
    
    .messages {
      text-align: left;
    }
    
    .message {
      margin: 5px 0;
    }
    
    input {
      padding: 10px;
      margin-right: 10px;
      width: 200px;
    }
    
    button {
      padding: 10px;
    }
    

    Step 4: Run Your Application

    In the terminal, run:

    npm start
    
  • Expense Tracker

    Step 1: Set Up Your React Project

    Open your terminal and run the following commands:

    npx create-react-app expense-tracker
    cd expense-tracker
    

    Step 2: Create the Expense Tracker Components

    Replace the content of src/App.js with the following code:

    import React, { useState } from 'react';
    import './App.css';
    
    const App = () => {
      const [expenses, setExpenses] = useState([]);
      const [description, setDescription] = useState('');
      const [amount, setAmount] = useState('');
    
      const addExpense = () => {
    
    if (description && amount) {
      setExpenses([...expenses, { description, amount: parseFloat(amount) }]);
      setDescription('');
      setAmount('');
    }
    }; const totalExpenses = expenses.reduce((acc, expense) => acc + expense.amount, 0); return (
    <div className="App">
      <h1>Expense Tracker</h1>
      <div className="input-container">
        <input
          type="text"
          placeholder="Description"
          value={description}
          onChange={(e) => setDescription(e.target.value)}
        />
        <input
          type="number"
          placeholder="Amount"
          value={amount}
          onChange={(e) => setAmount(e.target.value)}
        />
        <button onClick={addExpense}>Add Expense</button>
      </div>
      
      <h2>Total Expenses: ${totalExpenses.toFixed(2)}</h2>
      <ul>
        {expenses.map((expense, index) => (
          <li key={index}>
            {expense.description}: ${expense.amount.toFixed(2)}
          </li>
        ))}
      </ul>
    </div>
    ); }; export default App;

    Step 3: Style Your Expense Tracker

    Open src/App.css and add the following styles:

    body {
      margin: 0;
      font-family: Arial, sans-serif;
    }
    
    .App {
      text-align: center;
      padding: 20px;
    }
    
    .input-container {
      margin-bottom: 20px;
    }
    
    input {
      padding: 10px;
      margin-right: 10px;
      width: 200px;
    }
    
    button {
      padding: 10px;
    }
    
    ul {
      list-style-type: none;
      padding: 0;
    }
    
    li {
      margin: 10px 0;
    }
    
    h2 {
      margin-top: 20px;
    }
    

    Step 4: Run Your Application

    In the terminal, run:

    npm start
    
  • Blog Platform

    Set Up Your React Project

    Open your terminal and run the following commands:

    npx create-react-app blog-platform
    cd blog-platform
    

    Step 2: Install React Router

    You’ll need React Router for navigation:

    npm install react-router-dom
    

    Step 3: Create Blog Components

    Replace the content of src/App.js with the following code:

    import React from 'react';
    import { BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom';
    import './App.css';
    
    const postsData = [
      {
    
    id: 1,
    title: 'First Blog Post',
    content: 'This is the content of the first blog post.',
    }, {
    id: 2,
    title: 'Second Blog Post',
    content: 'This is the content of the second blog post.',
    }, {
    id: 3,
    title: 'Third Blog Post',
    content: 'This is the content of the third blog post.',
    }, ]; const Home = () => ( <div>
    &lt;h2>Blog Posts&lt;/h2>
    &lt;ul>
      {postsData.map((post) => (
        &lt;li key={post.id}>
          &lt;Link to={/post/${post.id}}>{post.title}&lt;/Link>
        &lt;/li>
      ))}
    &lt;/ul>
    </div> ); const Post = ({ match }) => { const post = postsData.find((p) => p.id === parseInt(match.params.id)); return (
    &lt;div>
      {post ? (
        &lt;>
          &lt;h2>{post.title}&lt;/h2>
          &lt;p>{post.content}&lt;/p>
          &lt;Link to="/">Go Back&lt;/Link>
        &lt;/>
      ) : (
        &lt;h2>Post not found&lt;/h2>
      )}
    &lt;/div>
    ); }; const App = () => { return (
    &lt;Router>
      &lt;div className="App">
        &lt;header className="header">
          &lt;h1>Blog Platform&lt;/h1>
          &lt;nav>
            &lt;Link to="/">Home&lt;/Link>
          &lt;/nav>
        &lt;/header>
        &lt;Switch>
          &lt;Route path="/" exact component={Home} />
          &lt;Route path="/post/:id" component={Post} />
        &lt;/Switch>
      &lt;/div>
    &lt;/Router>
    ); }; export default App;

    Step 4: Style Your Blog Platform

    Open src/App.css and add some basic styles:

    body {
      margin: 0;
      font-family: Arial, sans-serif;
    }
    
    .App {
      text-align: center;
      padding: 20px;
    }
    
    .header {
      background-color: #282c34;
      color: white;
      padding: 20px;
    }
    
    .header nav a {
      margin: 0 15px;
      color: white;
      text-decoration: none;
    }
    
    .header nav a:hover {
      text-decoration: underline;
    }
    
    h2 {
      margin-top: 20px;
    }
    
    ul {
      list-style-type: none;
      padding: 0;
    }
    
    li {
      margin: 10px 0;
    }
    
    footer {
      margin-top: 40px;
      padding: 20px 0;
      background-color: #f1f1f1;
    }
    

    Step 5: Run Your Application

    In the terminal, run:

    npm start
    
  • E-commerce Store

    Set Up Your React Project

    Open your terminal and run the following commands:

    npx create-react-app ecommerce-store
    cd ecommerce-store
    

    Step 2: Create the E-commerce Store Components

    Replace the content of src/App.js with the following code:

    import React, { useState } from 'react';
    import './App.css';
    
    const productsData = [
      { id: 1, name: 'Product 1', price: 29.99, image: 'https://via.placeholder.com/150' },
      { id: 2, name: 'Product 2', price: 39.99, image: 'https://via.placeholder.com/150' },
      { id: 3, name: 'Product 3', price: 49.99, image: 'https://via.placeholder.com/150' },
    ];
    
    const App = () => {
      const [cart, setCart] = useState([]);
    
      const addToCart = (product) => {
    
    setCart(&#91;...cart, product]);
    }; const getCartCount = () => {
    return cart.length;
    }; return (
    &lt;div className="App">
      &lt;header className="header">
        &lt;h1>E-commerce Store&lt;/h1>
        &lt;div className="cart">
          &lt;span>Cart: {getCartCount()} items&lt;/span>
        &lt;/div>
      &lt;/header>
      &lt;main>
        &lt;h2>Products&lt;/h2>
        &lt;div className="product-list">
          {productsData.map((product) => (
            &lt;div key={product.id} className="product-card">
              &lt;img src={product.image} alt={product.name} />
              &lt;h3>{product.name}&lt;/h3>
              &lt;p>${product.price.toFixed(2)}&lt;/p>
              &lt;button onClick={() => addToCart(product)}>Add to Cart&lt;/button>
            &lt;/div>
          ))}
        &lt;/div>
      &lt;/main>
      &lt;footer>
        &lt;p>&amp;copy; 2024 E-commerce Store&lt;/p>
      &lt;/footer>
    &lt;/div>
    ); }; export default App;

    Step 3: Style Your Store

    Open src/App.css and add the following styles:

    body {
      margin: 0;
      font-family: Arial, sans-serif;
    }
    
    .App {
      text-align: center;
      padding: 20px;
    }
    
    .header {
      background-color: #282c34;
      color: white;
      padding: 20px;
    }
    
    .header .cart {
      margin-top: 10px;
    }
    
    .product-list {
      display: flex;
      justify-content: center;
      flex-wrap: wrap;
    }
    
    .product-card {
      border: 1px solid #ccc;
      border-radius: 8px;
      margin: 10px;
      padding: 10px;
      width: 200px;
      text-align: center;
    }
    
    .product-card img {
      width: 100%;
      height: auto;
    }
    
    footer {
      margin-top: 40px;
      padding: 20px 0;
      background-color: #f1f1f1;
    }
    

    Step 4: Run Your Application

    In the terminal, run:

    npm start
    
  • Personal Portfolio

    Step 1: Set Up Your React Project

    Open your terminal and run the following commands:

    bashCopy codenpx create-react-app portfolio
    cd portfolio
    

    Step 2: Create the Portfolio Components

    Replace the content of src/App.js with the following code:

    javascriptCopy codeimport React from 'react';
    import './App.css';
    
    const App = () => {
      return (
    
    &lt;div className="App"&gt;
      &lt;header className="header"&gt;
        &lt;h1&gt;Your Name&lt;/h1&gt;
        &lt;p&gt;Your Tagline or a short bio goes here.&lt;/p&gt;
        &lt;nav&gt;
          &lt;a href="#projects"&gt;Projects&lt;/a&gt;
          &lt;a href="#skills"&gt;Skills&lt;/a&gt;
          &lt;a href="#contact"&gt;Contact&lt;/a&gt;
        &lt;/nav&gt;
      &lt;/header&gt;
      &lt;section id="projects"&gt;
        &lt;h2&gt;Projects&lt;/h2&gt;
        &lt;div className="project-list"&gt;
          &lt;div className="project-card"&gt;
            &lt;h3&gt;Project Title 1&lt;/h3&gt;
            &lt;p&gt;Description of project 1.&lt;/p&gt;
            &lt;a href="https://github.com/yourusername/project1" target="_blank" rel="noopener noreferrer"&gt;View Project&lt;/a&gt;
          &lt;/div&gt;
          &lt;div className="project-card"&gt;
            &lt;h3&gt;Project Title 2&lt;/h3&gt;
            &lt;p&gt;Description of project 2.&lt;/p&gt;
            &lt;a href="https://github.com/yourusername/project2" target="_blank" rel="noopener noreferrer"&gt;View Project&lt;/a&gt;
          &lt;/div&gt;
          {/* Add more projects as needed */}
        &lt;/div&gt;
      &lt;/section&gt;
      &lt;section id="skills"&gt;
        &lt;h2&gt;Skills&lt;/h2&gt;
        &lt;ul&gt;
          &lt;li&gt;JavaScript&lt;/li&gt;
          &lt;li&gt;React&lt;/li&gt;
          &lt;li&gt;CSS&lt;/li&gt;
          &lt;li&gt;HTML&lt;/li&gt;
          {/* Add more skills as needed */}
        &lt;/ul&gt;
      &lt;/section&gt;
      &lt;footer id="contact"&gt;
        &lt;h2&gt;Contact Me&lt;/h2&gt;
        &lt;p&gt;Email: [email protected]&lt;/p&gt;
        &lt;p&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/yourprofile" target="_blank" rel="noopener noreferrer"&gt;Your LinkedIn&lt;/a&gt;&lt;/p&gt;
        &lt;p&gt;GitHub: &lt;a href="https://github.com/yourusername" target="_blank" rel="noopener noreferrer"&gt;Your GitHub&lt;/a&gt;&lt;/p&gt;
      &lt;/footer&gt;
    &lt;/div&gt;
    ); }; export default App;

    Step 3: Style Your Portfolio

    Open src/App.css and add the following styles:

    cssCopy codebody {
      margin: 0;
      font-family: Arial, sans-serif;
    }
    
    .App {
      text-align: center;
      padding: 20px;
    }
    
    .header {
      background-color: #282c34;
      color: white;
      padding: 50px 0;
    }
    
    .header h1 {
      margin: 0;
    }
    
    .header nav a {
      margin: 0 15px;
      color: white;
      text-decoration: none;
    }
    
    header nav a:hover {
      text-decoration: underline;
    }
    
    section {
      margin: 40px 0;
    }
    
    .project-list {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
    }
    
    .project-card {
      border: 1px solid #ccc;
      border-radius: 8px;
      margin: 10px;
      padding: 10px;
      width: 200px;
    }
    
    .project-card h3 {
      margin: 0;
    }
    
    footer {
      margin-top: 40px;
      padding: 20px 0;
      background-color: #f1f1f1;
    }
    

    Step 4: Run Your Application

    In the terminal, run:

    bashCopy codenpm start
    
  • Recipe Sharing Platform

    • Features:
      • User-generated recipes with images
      • Search and filter by ingredients or cuisine
      • Comment and rating system
      • Save favorite recipes to user profile
    • Technologies:
      • REST API or GraphQL for backend
      • Image uploads with Cloudinary or similar service
      • Responsive design for mobile compatibility
  • Recipe Finder

    Set Up Your React Project

    Open your terminal and create a new React app:

    bashCopy codenpx create-react-app recipe-finder
    cd recipe-finder
    

    Step 2: Get Your API Key

    1. Sign up at Edamam.
    2. Create a new application to get your App ID and App Key.

    Step 3: Create the Recipe Finder Component

    Replace the content of src/App.js with the following code:

    javascriptCopy codeimport React, { useState } from 'react';
    import './App.css';
    
    const App = () => {
      const [query, setQuery] = useState('');
      const [recipes, setRecipes] = useState([]);
      const [error, setError] = useState('');
    
      const APP_ID = 'YOUR_APP_ID'; // Replace with your Edamam App ID
      const APP_KEY = 'YOUR_APP_KEY'; // Replace with your Edamam App Key
    
      const fetchRecipes = async () => {
    
    if (!query) return;
    try {
      const response = await fetch(https://api.edamam.com/search?q=${query}&amp;amp;app_id=${APP_ID}&amp;amp;app_key=${APP_KEY});
      const data = await response.json();
      if (data.hits.length === 0) {
        setError('No recipes found.');
      } else {
        setRecipes(data.hits);
        setError('');
      }
    } catch (err) {
      setError('Failed to fetch recipes.');
    }
    }; const handleKeyPress = (e) => {
    if (e.key === 'Enter') {
      fetchRecipes();
    }
    }; return (
    &lt;div className="App"&gt;
      &lt;h1&gt;Recipe Finder&lt;/h1&gt;
      &lt;input
        type="text"
        value={query}
        onChange={(e) =&gt; setQuery(e.target.value)}
        onKeyPress={handleKeyPress}
        placeholder="Enter ingredients..."
      /&gt;
      &lt;button onClick={fetchRecipes}&gt;Search&lt;/button&gt;
      {error &amp;&amp; &lt;p className="error"&gt;{error}&lt;/p&gt;}
      &lt;div className="recipe-list"&gt;
        {recipes.map((item) =&gt; (
          &lt;div key={item.recipe.label} className="recipe-card"&gt;
            &lt;h2&gt;{item.recipe.label}&lt;/h2&gt;
            &lt;img src={item.recipe.image} alt={item.recipe.label} /&gt;
            &lt;p&gt;Calories: {Math.round(item.recipe.calories)}&lt;/p&gt;
            &lt;a href={item.recipe.url} target="_blank" rel="noopener noreferrer"&gt;View Recipe&lt;/a&gt;
          &lt;/div&gt;
        ))}
      &lt;/div&gt;
    &lt;/div&gt;
    ); }; export default App;

    Step 4: Style Your App

    Open src/App.css and add some styles:

    cssCopy code.App {
      text-align: center;
      margin: 20px;
      font-family: Arial, sans-serif;
    }
    
    input {
      padding: 10px;
      margin-right: 10px;
      width: 200px;
    }
    
    button {
      padding: 10px;
    }
    
    .error {
      color: red;
    }
    
    .recipe-list {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
    }
    
    .recipe-card {
      border: 1px solid #ccc;
      border-radius: 8px;
      margin: 10px;
      padding: 10px;
      width: 200px;
    }
    
    .recipe-card img {
      width: 100%;
      border-radius: 8px;
    }
    

    Step 5: Run Your Application

    In the terminal, run:

    bashCopy codenpm start
    
  • Weather App

    Step 1: Set Up Your React Project

    Open your terminal and run the following commands:

    bashCopy codenpx create-react-app weather-app
    cd weather-app
    

    Step 2: Get Your API Key

    1. Go to OpenWeatherMap and sign up for a free account.
    2. After logging in, navigate to the API section and get your API key.

    Step 3: Create the Weather App Component

    Open src/App.js and replace its content with the following code:

    javascriptCopy codeimport React, { useState } from 'react';
    import './App.css';
    
    const App = () => {
      const [city, setCity] = useState('');
      const [weather, setWeather] = useState(null);
      const [error, setError] = useState('');
    
      const API_KEY = 'YOUR_API_KEY'; // Replace with your OpenWeatherMap API key
    
      const handleInputChange = (e) => {
    
    setCity(e.target.value);
    }; const fetchWeather = async () => {
    if (!city) return;
    try {
      const response = await fetch(https://api.openweathermap.org/data/2.5/weather?q=${city}&amp;amp;appid=${API_KEY}&amp;amp;units=metric);
      if (!response.ok) {
        throw new Error('City not found');
      }
      const data = await response.json();
      setWeather(data);
      setError('');
    } catch (err) {
      setError(err.message);
      setWeather(null);
    }
    }; const handleKeyPress = (e) => {
    if (e.key === 'Enter') {
      fetchWeather();
    }
    }; return (
    &lt;div className="App"&gt;
      &lt;h1&gt;Weather App&lt;/h1&gt;
      &lt;input
        type="text"
        value={city}
        onChange={handleInputChange}
        onKeyPress={handleKeyPress}
        placeholder="Enter city name..."
      /&gt;
      &lt;button onClick={fetchWeather}&gt;Get Weather&lt;/button&gt;
      {error &amp;&amp; &lt;p className="error"&gt;{error}&lt;/p&gt;}
      
      {weather &amp;&amp; (
        &lt;div className="weather-info"&gt;
          &lt;h2&gt;{weather.name}&lt;/h2&gt;
          &lt;p&gt;Temperature: {weather.main.temp} °C&lt;/p&gt;
          &lt;p&gt;Weather: {weather.weather&#91;0].description}&lt;/p&gt;
          &lt;p&gt;Humidity: {weather.main.humidity} %&lt;/p&gt;
          &lt;p&gt;Wind Speed: {weather.wind.speed} m/s&lt;/p&gt;
        &lt;/div&gt;
      )}
    &lt;/div&gt;
    ); }; export default App;

    Step 4: Style Your App

    Open src/App.css and add some basic styles:

    cssCopy code.App {
      text-align: center;
      margin: 20px;
      font-family: Arial, sans-serif;
    }
    
    input {
      padding: 10px;
      margin-right: 10px;
      width: 200px;
    }
    
    button {
      padding: 10px;
    }
    
    .weather-info {
      margin-top: 20px;
    }
    
    .error {
      color: red;
    }
    

    Step 5: Run Your Application

    In the terminal, run:

    bashCopy codenpm start
    
  • Todo List App

    Step 1: Set Up Your React Project

    Open your terminal and run the following commands:

    bashCopy codenpx create-react-app todo-list
    cd todo-list
    

    Step 2: Create the Todo List Component

    Open src/App.js and replace its content with the following code:

    javascriptCopy codeimport React, { useState } from 'react';
    import './App.css';
    
    const App = () => {
      const [tasks, setTasks] = useState([]);
      const [inputValue, setInputValue] = useState('');
    
      const handleInputChange = (e) => {
    
    setInputValue(e.target.value);
    }; const handleAddTask = () => {
    if (inputValue.trim()) {
      setTasks(&#91;...tasks, { text: inputValue, completed: false }]);
      setInputValue('');
    }
    }; const handleToggleTask = (index) => {
    const newTasks = &#91;...tasks];
    newTasks&#91;index].completed = !newTasks&#91;index].completed;
    setTasks(newTasks);
    }; const handleDeleteTask = (index) => {
    const newTasks = tasks.filter((_, i) =&gt; i !== index);
    setTasks(newTasks);
    }; return (
    &lt;div className="App"&gt;
      &lt;h1&gt;Todo List&lt;/h1&gt;
      &lt;input
        type="text"
        value={inputValue}
        onChange={handleInputChange}
        placeholder="Add a new task..."
      /&gt;
      &lt;button onClick={handleAddTask}&gt;Add Task&lt;/button&gt;
      &lt;ul&gt;
        {tasks.map((task, index) =&gt; (
          &lt;li key={index} style={{ textDecoration: task.completed ? 'line-through' : 'none' }}&gt;
            &lt;span onClick={() =&gt; handleToggleTask(index)}&gt;{task.text}&lt;/span&gt;
            &lt;button onClick={() =&gt; handleDeleteTask(index)}&gt;Delete&lt;/button&gt;
          &lt;/li&gt;
        ))}
      &lt;/ul&gt;
    &lt;/div&gt;
    ); }; export default App;

    Step 3: Style Your App

    Open src/App.css and add some basic styles:

    cssCopy code.App {
      text-align: center;
      margin: 20px;
      font-family: Arial, sans-serif;
    }
    
    input {
      padding: 10px;
      margin-right: 10px;
      width: 200px;
    }
    
    button {
      padding: 10px;
    }
    
    ul {
      list-style-type: none;
      padding: 0;
    }
    
    li {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin: 10px 0;
    }
    

    Step 4: Run Your Application

    In the terminal, run:

    bashCopy codenpm start
  • Participate in the Community

    • Engage with the C++ community through forums, blogs, and conferences. This helps you learn from others and share your knowledge.