1.1.1 • Published 6 years ago

react-china-location v1.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

react-china-location npm

React Component for china-location

It uses the simple html select/option tag, to use custom UI, install the china-location only and make your own UI component.

demo

Usage

npm install china-location react-china-location --save or yarn add china-location react-china-location

import locationData from 'china-location/dist/location.json';
import ChinaLocation from 'react-china-location';

class App extends React.Component {
  constructor (props) {
    super(props);

    this.onLocationChange = this.onLocationChange.bind(this);

    this.state = {
      currentLocation: {},
    }
  }


  onLocationChange (newLocation) {
    //{
    //  province: {code: '110000', name: '北京市'},
    //  city: {code: '110000', name: '北京市'},
    //  district: {code: '110101', name: '东城区'}
    //}
    console.log(newLocation);
    this.setState({
      currentLocation: newLocation,
    });
  }

  render () {
    <div>
      <ChinaLocation list={locationData} onLocationChange={this.onLocationChange}/>
    </div>
  }
}

Props

  • list: location data from china-location
  • onLocationChange: be notified when user select different option

Demo

Go to demo/build and open index.html in your browser.

LICENSE

MIT

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

7 years ago

0.0.7

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago