npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

state-district-component

v1.0.3

Published

A React Library for fetching States and districts of India

Downloads

8

Readme

Getting Started

A React Library for fetching States and districts of India. npm i state-district-component.

With create-react-app

create-react-app is a popular CLI tool to getting started with React. If you're new to React or Webpack, you might be starting out here. This section will walk you through configuring create-react-app to install and use our components.

If you're using an older version (v1) of create-react-app, please refer to our create-react-app-v1 doc.

Recommended things to know

  1. node/npm
  2. JavaScript
  3. HTML/CSS
  4. ES6

NOTE: If you haven't used create-react-app before, you may want to read the Overview Guide.

Step 1: Install Components

Install Component:

npm i state-district-component

Step 2: Use State and District Components

import React, { useState } from "react";
import "./App.css";
import { States, Districts } from "state-district-component";
const App = () => {
  const [state, setState] = useState();
  const [district, setDistrict] = useState();
  const styles = {
    // pass the styles in the style props of component
    width: "230px",
    outline: "none",
    padding: "10px",
    background: "rgb(227, 226, 226)",
    border: "none",
    borderRadius: "6px",
  };
  const getStateValue = (value) => {
    // for geting  the input value pass the function in oChnage props and you will get value back from component
    setState(value);
  };
  const getDistrictValue = (value) => {
    setDistrict(value);
  };
  return (
    <>
      <States styles={styles} onChange={getStateValue} />
      <Districts state={state} onChange={getDistrictValue} />
      {/*pass the state props to District component the name of state for which you want to get districts */}
    </>
  );
};

export default App;

Components

| Component | Props | | --------- | ------------------------------- | | States | className , styles ,onChange | | District | className,style ,onChange,State |

Porps Usage

| Porp | Usage | | --------- | ----------------------------------------------------------------------------------------------------- | | className | pass className prop to give input component a class name and you can style it by targeting class name | | styles | you can pass style project to get style to input | | state | pass the state prop only for District component for Indian state which you want to get districts | | onChange | will give back the value of the input |

Other usage

Geting arrays of state and districts

import { allStates, allDistricts } from "state-district-component";
Above imports are array of state and distrct you can use it for your project if you dont want to use States and Districts components ,if you want make custom comoponents