Package Exports
- country-state-city-nextjs
- country-state-city-nextjs/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (country-state-city-nextjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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-nextjsImport
import {
countryProps,
stateProps,
cityProps,
useCSCProps,
loadCountrys,
loadStates,
loadCitys,
useCSC,
} from "country-state-city-nextjs";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();
}, []);Use in multiple components
import { useLocalStorage } from "uselocalstoragenextjs";
import Component from "./component";
const Home = () => {
const { value, setLocalStorage, load } = useLocalStorage({
name: "cart",
defaultValue: [],
parse: (v: any) => {
return JSON.parse(v == "" ? "[]" : v);
},
updateValue(olValue, newValue) {
return [...olValue, newValue];
},
});
return (
<div>
Cart
<div>{JSON.stringify(value)}</div>
<br />
<button
onClick={() => {
setLocalStorage({ p: 1 });
}}
>
Add New Product
</button>
<Component />
</div>
);
};
export default Home;import { useLocalStorage } from "uselocalstoragenextjs";
export default () => {
const { value, load } = useLocalStorage({
name: "cart",
defaultValue: [],
parse: (v: any) => {
return JSON.parse(v == "" ? "[]" : v);
},
});
return (
<>
{load && (
<>
N Items in Cart
<br />
{value.length}
</>
)}
</>
);
};Developer
Email blancofrancisco34@gmail.com