country-state-city-nextjs
This is a library for get all countrys, states and citys of world.
Installing
Using npm:
npm i country-state-city-nextjs
Import
import {
load,
countryProps,
stateProps,
cityProps,
useCSCProps,
loadCountrys,
loadStates,
loadCitys,
useCSC,
} from "country-state-city-nextjs/cjs/index";
Use
const [CSC, setCSC] = useState<{
countrys: countryProps[];
states: stateProps[];
citys: cityProps[];
}>({
countrys: [],
states: [],
citys: [],
});
const loadCSC = async () => {
const countrys: countryProps[] = await loadCountrys();
const states: stateProps[] = await loadStates();
const citys: cityProps[] = await loadCitys();
setCSC({
countrys,
states,
citys,
});
};
useEffect(() => {
loadCSC();
}, []);
useCSC
const {
load,
countrySelected,
stateSelected,
citySelected,
countrys,
states,
citys,
onChangeCSC,
statesForCountrySelected
citysForStateSelected
} = useCSC({
defaultCountry: {
id: 82,
text: "Colombia",
},
defaultState: {
id: 1700,
id_country: 82,
text: "Antioquia",
},
defaultCity: {
id: 465167,
id_state: 1700,
text: "Medellín",
},
});
onChangeCSC
onChangeCSC.country({
id: 95,
text: "Venezuela",
});
onChangeCSC.state({
id: 1861,
id_country: 95,
text: "Táchira",
});
onChangeCSC.city({
id: 590202,
id_state: 1861,
text: "Peracal",
});
Developer
Francisco Blanco
Gitlab franciscoblancojn
Email blancofrancisco34@gmail.com
Repositories