GithubHelp home page GithubHelp logo

sanjaraiy / contextlocal Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 42 KB

This repository features a project built with JavaScript, Tailwind CSS, React, and React-Redux. Enjoy responsiveness across different devices with enhanced state management and dynamic UI! ๐Ÿ“ฑ๐Ÿ’ป

JavaScript 88.65% HTML 9.80% CSS 1.55%
context-api javascript react-redux reactjs redux responsive-design tailwindcss

contextlocal's Introduction

Todo Application Using React

This project is built on JavaScript, Tailwind, React and React-Redux.It is responsive for different devices.

Install Vite :-

vite@latest

Install Node-Modules :-

npm install

Tailwind Install Link :-

npm install -D tailwindcss
npx tailwindcss init

Tailwind Configure your template paths :-

module.exports = {
  content: ["./src/**/*.{html,js}"],
  theme: {
    extend: {},
  },
  plugins: [],
}

Add the Tailwind directives to your CSS :-

@tailwind base;
@tailwind components;
@tailwind utilities;

Install React-Redux :-

npm i react-redux

Features :-

  • Add new todo.
  • Update existing todo.
  • Save todo in local Storage.
  • Delete todo from a list.
  • Toggle an existing todo.

Contexts :-

Index.js :-

import {TodoContext, Todoprovider, useTodo } from './TodoContext'

export {
    TodoContext,
    Todoprovider,
    useTodo
}

TodoContext.js :-

import {createContext, useContext} from "react";

export const TodoContext = createContext({
     todos : [
        {
            id : 1,
            todo : "Todo msg",
            completed : false,
        },
     ],
     addTodo : (todo) => {},
     updatedTodo : (id, todo) => {},
     deleteTodo : (id) => {},
     toggleComplete : (id) => {}
})

export const useTodo = () => {
    return useContext(TodoContext)
}

export const Todoprovider = TodoContext.Provider

App.js :-

import { useState } from 'react'
import { Todoprovider } from './contexts'
import { useEffect } from 'react'

function App() {
  
  const [todos, setTodos] = useState([])

  const addTodo = (todo) => {
       setTodos((prev) => [{id: Date.now(),...todo}, ...prev])
  }

  const updatedTodo = (id, todo) => {
       setTodos((prev) => prev.map((prevTodo) => (prevTodo.id === id ? todo : prevTodo)))

  }

  const deleteTodo = (id) => {
      setTodos((prev) => prev.filter((todo) => todo.id !== id))
  }

  const toggleComplete = (id) => {
      setTodos((prev) => prev.map((prevTodo) => prevTodo === id ? { ...prevTodo, completed : !prevTodo.completed} : prevTodo))
  }

  useEffect(() => {
   const todos = JSON.parse(localStorage.getItem("todos"))
   if(todos && todos.length > 0){
      setTodos(todos)
   }
  },[])

  useEffect( () => {
    localStorage.setItem("todos", JSON.stringify(todos))

  }, [todos])
  
  return (
    <Todoprovider value = {{todos, addTodo, updatedTodo, deleteTodo, toggleComplete}}>
       <div className = "bg-[#172842] min-h-screen py-8">
       <div className = "w-full max-w-2xl mx-auto shadow-md rounded-lg px-4 py-3 text-white">
        <h1 className = "text-2xl font-bold text-center mb-8 mt-2">Manage Your Todos</h1>
        <div className = "mb-4">
            {/* Todo form goes here */} 
        </div>
        <div className = "flex flex-wrap gap-y-3">
            {/*Loop and Add TodoItem here */}
        </div>
    </div>
   </div>
    </Todoprovider>
   
  )
}

export default App

contextlocal's People

Contributors

sanjaraiy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.