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

Routing in React using React-Router Version 6

 Routing in React using React-Router Version 6

What is Routing?

- The process of navigating a user to different pages based on their request is known as routing.

- Routing is a process of binding a web URL to specific resource. In react we can say, "it is a binding of URL to a specific component.

- As react is a user interface library, it does not support routing.

- In this post, we will learn about "routing in react using react-router-dom library version 6".

Install React Router Command

npm install react-router-dom --save

Main component used for Navigation

1) BrowserRouter as Router - top level component 

2) Routes - Replacement of Switch component.

3) Route - child component of Routes, useful for mapping a specific URL to a component.

4) Link - Similar to anchor tag in html.

Note: 

Switch Component is deprecated from version 6. The new component is introduced called as Routes.

routing-in-react-using-react-router-version-6
Multiple Routing in React Js

Installation:

 npm install react-router-dom --save

Sample Code:

A) App.js

import React from 'react';
import { BrowserRouterRoutesRouteLinkNavigate } from 'react-router-dom';
import Home from './Home';
import About from './AboutUs';
import ContactUs from './ContactUs';
import PageNotFound from './PageNotFound';

function App() {
  return (
    <BrowserRouter>
      <nav id="navbar">
        <Link id="link1" to="/">
          Home
        </Link>
        <Link id="link2" to="about">
          About Us
        </Link>
        <Link id="link3" to="contact">
          Contact Us
        </Link>
      </nav>

      <Routes>
        <Route exact path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
        <Route path="/contact" element={<ContactUs />} />
        <Route path="*" element={<PageNotFound />} />
      </Routes>
    </BrowserRouter>
  );
}

export default App;

B) Home.js


import React from 'react';
import './style.css';

function Home() {
  return <div id="home">Home Page Body</div>;
}

export default Home;

C) AboutUs.js

import React from 'react';
import './style.css';

const AboutUs = () => {
  return <div id="aboutus">About Us Page</div>;
};

export default AboutUs;

D) ContactUs.js

import React from 'react';
import './style.css';

function ContactUs() {
  return <div id="contactus">Contact Us Page</div>;
}

export default ContactUs;

E) PageNotFound.js

import React from 'react';

function PageNotFound() {
  return <div id="pagenotfound">Page Not Found Page</div>;
}

export default PageNotFound;

F) style.css

#home,
#aboutus,
#contactus,
#pagenotfound {
  border1px solid black;
  width250px;
  height100px;
  line-height100px;
  align-itemscenter;
  justify-contentcenter;
  padding-left150px;
}

#navbar {
  margin-left1px;
  margin-bottom5px;
  width395px;
  border1px solid black;
  padding2px;
  background-colorblack;

}

#link1,
#link2,
#link3 {
  padding20px;
  colororange;
}

G) package.json

{
  "name""routing-in-react",
  "version""0.1.0",
  "private"true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^6.2.1",
    "react-scripts": "5.0.0",
    "web-vitals": "^2.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }
}


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?

Environment Setup and Installation for React Js Application

Create a custom calendar in React Js | Interview Question