npm.io
1.0.1 • Published 7 years ago

react-country-suggest

Licence
ISC
Version
1.0.1
Deps
4
Size
1.7 MB
Vulns
24
Weekly
0

Country Suggest react.js component

image

By default component will use https://restcountries.eu/ API

Usage

  <CountrySelect 
     apiURL="https://restcountries.eu/rest/v2/name/"
     nameField="name" 
     flagField="flag" 
     dataCallback={callback}
  />,

Parameters

Property Default value Description
apiURL https://restcountries.eu/rest/v2/name/ url for getting data, user's input will be appended to the end of a string
nameField "name" name of field with country name in the returned json object.
flagField "flag" name of field with link to flag icon in the returned json object
dataCallback "null" callback function for modification of data from response
dataCallback

Callback function takes single object from collection of data recieved from API, and should return an object with name and flag properties.

Here is an example of a callback function that uses nativeName property instead of name, and shiny flags from https://www.countryflags.io/

  var callback = function dataManage(resp){
    let data = {
      name: resp.nativeName,
      flag: "https://www.countryflags.io/" + resp.alpha2Code + "/shiny/64.png",
    }
    return data;
  }
  
  ...
  
  <CountrySelect dataCallback={callback} />,