Understanding and Implementing Schemas in Python

Understanding and Implementing Schemas in Python Introduction In the world of programming, particularly in the context of data management and validation, schemas play a vital role. A schema is essentially a blueprint or a predefined structure that defines the expected format, data types, and constraints for a given data entity. In this blog, we will delve into the concept of schemas in Python, exploring what they are, why they are important, and how you can implement them in your projects. What is a Schema? A schema serves as a contract between different components of a system, ensuring that data is consistent, valid, and well-structured. It defines the rules for how data should be organized, what fields it should contain, and what types of values those fields can hold. In essence, a schema acts as a set of rules that data must adhere to in order to be considered valid. Why Are Schemas Important? Data Validation: Schemas provide a way to validate incoming data. When data is received o

Create a ToDo App in React Js | Interview Question

Create a ToDo App in React Js | Interview Question

In this post, you will learn about how to create To-Do App in React using hooks.

I have use arrays of object to save to do list, not redux and required some basic packages like Node and npm.

Following is the UI functionality of the application.

todoapp
Todo App in React Js



Componets: 
   There are four component created in our application.
   a) ToDoHeader: Created for showing details of Header section.
   b) AddToItem: Created for adding text to "ToDo list".
   c) AddToDoList: Created for showing "ToDo list".
   d) ToDoFooter: Created for showing details of Footer section.

Sample Code:

1) App.js

import React, { useState } from 'react';
import './style.css';

window.id = 0;

const ToDoHeader = () => {
  return <div id="todoHeader"> To Do Applicaation </div>;
};

const AddToItem = (props=> {
  const { textsetText } = props;
  return (
    <>
      <div id="todoAdd">
        <input
          id="todoInput"
          type="text"
          value={text}
          onChange={(e=> {
            setText(e.target.value);
          }}
        />
        <button
          id="save"
          type="submit"
          onClick={() => {
            props.addItem(text);
          }}
        >
          {props.btnName}
        </button>
      </div>
    </>
  );
};

const AddToDoList = (props=> {
  const { deleteTodoEditTododata } = props;

  return (
    <>
      {data &&
        data.length > 0 &&
        data.map((item=> {
          return (
            <>
              <div id="todoListItem">
                <label> {item.todoName} </label>
              </div>
              <div id="todoEditDelete">
                <button
                  id="delete"
                  type="submit"
                  onClick={() => {
                    deleteTodo(item.todoId);
                  }}
                >
                  Delete
                </button>
                <button
                  id="edit"
                  type="submit"
                  onClick={() => {
                    EditTodo(item.todoId);
                  }}
                >
                  Edit{' '}
                </button>
              </div>
            </>
          );
        })}
    </>
  );
};

const ToDoFooter = (props=> {
  const { clearAll } = props;
  return (
    <div id="todoFooter">
      <button
        type="submit"
        onClick={() => {
          clearAll();
        }}
      >
        Clear All
      </button>
    </div>
  );
};

export default function App() {
  const [textsetText] = useState('');
  const [datasetData] = useState([]);
  const [btnNamesetBtnName] = useState('Save');
  const [editIdsetEditId] = useState(0);

  const addItem = () => {
    if (btnName == 'Save') {
      let obj = { todoId: window.id++, todoName: text };
      let aa = [...dataobj];
      setData(aa);
    } else {
      data.forEach((v=> {
        if (v.todoId === editIdv.todoName = text;
      });
      setData(data);
    }
    setBtnName('Save');
    setEditId(0);
  };

  const deleteTodo = (id=> {
    const delItem = data.filter((item=> {
      return item.todoId != id;
    });
    setData(delItem);
  };

  const EditTodo = (id=> {
    setEditId(id);

    const editItem = data.filter((item=> {
      return item.todoId == id;
    });
    let edittedText = editItem[0].todoName;
    setText(edittedText);
    setBtnName('Update');
  };

  const clearAll = () => {
    setData([]);
  };

  return (
    <div>
      <ToDoHeader />
      <br />

      <AddToItem
        btnName={btnName}
        addItem={addItem}
        setText={setText}
        text={text}
      />
      <br />

      <AddToDoList data={data} EditTodo={EditTodo} deleteTodo={deleteTodo} />
      <br />

      {data && data.length > 0 && <ToDoFooter clearAll={clearAll} />}
    </div>
  );
}

2) style.css

#todoHeader,
#todoFooter {
  width470px;
  height30px;
  border1px solid black;
  text-aligncenter;
  line-height30px;
  background-colororange;
  border-radius10px;
}
#todoListItem {
  width330px;
  height30px;
  border1px solid black;
  background-coloryellow;
  margin-top10px;
  border-radius10px;
  border-left-width10px;
  border-left-colorgreen;
  floatleft;
}

#todoEditDelete {
  width120px;
  height30px;
  border1px solid black;
  margin-left350px;
  margin-top10px;
  align-itemscenter;
  justify-contentcenter;
  displayflex;
  border-radius10px;
  background-coloryellow;
}

#delete,
#edit,
#save {
  margin-right1px;
  border-radius9px;
}

#todoAdd {
  width470px;
  height30px;
  border1px solid black;
  border-radius10px;
}

#todoInput {
  margin-left10px;
  margin-top5px;
  width370px;
  margin-right10px;
}



Happy Learning!! Happy Coding!!

Comments

Popular posts from this blog

useNavigate and useLocation hooks react-router-dom-v6

How to implement error boundaries in React Js

Pass data from child component to its parent component in React Js

Create a Shopping Item App using React Js and Xstate

Localization in React Js

How to fetch data from an API using fetch() method in React Js

How to fetch data using Axios Http Get Request in React Js?

Routing in React using React-Router Version 6

Environment Setup and Installation for React Js Application

Create a custom calendar in React Js | Interview Question