Skip to content

Instantly share code, notes, and snippets.

@Iheanacho-ai
Created April 13, 2022 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Iheanacho-ai/b4a1a5a5a88172f538e745b95176def0 to your computer and use it in GitHub Desktop.
Save Iheanacho-ai/b4a1a5a5a88172f538e745b95176def0 to your computer and use it in GitHub Desktop.
import {Appwrite} from "appwrite";
import {useState } from 'react';
import './App.css';
const App = () => {
const [countries, setCountries] = useState(["country"])
const [buttons, setButtons] = useState([
{
name: "English",
id: "en"
},
{
name: "Arabic",
id: "ar"
},
{
name: "Chinese - China",
id: "zh-cn"
},
{
name: "Slovenian",
id: "sl"
},
{
name: "Turkish",
id: "tr"
},
])
const sdk = new Appwrite();
sdk
.setEndpoint('http://localhost/v1') // Your API Endpoint
.setProject('6251d12c44f38f85595c') // Your project ID
;
const getCountries = async (e) => {
try {
let buttonId = e.target.id
sdk.setLocale(buttonId)
let promise = await sdk.locale.getCountries()
setCountries([])
promise.countries.map((country)=> setCountries(prevArray => [...prevArray, country.name]))
} catch (error) {
console.log(error)
}
}
return (
<div className="App">
<div className="app-container">
<h2>Choose your Language</h2>
<div className="button-container">
{
buttons.map(({name, id}) => (
<button id={id} onClick={getCountries}>{name}</button>
))
}
</div>
<select name="countries" id="countries-list">
{
countries.map((country) => (
<option value="country">{country}</option>
))
}
</select>
</div>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment