venkatmcajj / react-country-state-city

MIT License
14 stars 10 forks source link

Support for hosting the country and states json files locally #12

Closed dheeraj-qasource-inhabitiq closed 1 day ago

dheeraj-qasource-inhabitiq commented 1 week ago

Can we add support for hosting the json file on our own servers instead of making api calls to github.io? Like this package has here https://github.com/replaysMike/react-country-state-dropdown?tab=readme-ov-file#data By default, the control will load the github hosted data files. Alternatively, you can download the data zip file and host it yourself. Simply unzip the JSON files, and supply the src property to each control to tell it where to download from.

venkatmcajj commented 1 week ago

that is not advisable, if supplied a different json file means it will crash the app. For example mistakenly if you supplied a states json file for country dropdown means there is no key called emoji in state json but country dropdown will search for and it will make issues. That's why we directly binded the links.

dheeraj-qasource-inhabitiq commented 1 week ago

How about we just pass the path to the data folder and our code checks whether to load the country or state or city json file based on the component it's called from?

venkatmcajj commented 1 week ago

What if there is no json files available?. Please explain your issue with current method or what is the advantage of your suggestion, it will easy to understand and i can tell the solution for it.

dheeraj-qasource-inhabitiq commented 1 week ago

The issue with current method is, I am using this package on a secure payment page and I don't want to make any external api calls, and also one day github was down for a moment and the country and states dropdowns stopped working for a moment. that's why I am concerned.

and the solution I was thinking is

<CountrySelect onChange={(e) => { setCountryid(e.id); }} placeHolder="Select Country" src="/path/to/data-folder/" />

src will be optional, and if src is not provided then fallback to github.io links

venkatmcajj commented 1 week ago

Ok now it's make sense, sure i'll work on it.

dheeraj-qasource-inhabitiq commented 1 week ago

you can take a look at this plugin for reference, this guy has done the same thing with the src attribute https://github.com/replaysMike/react-country-state-dropdown also please let me know if you need any help from me,

venkatmcajj commented 1 day ago

Updated.