Skip to content

Instantly share code, notes, and snippets.

@alejovdev
Created December 9, 2019 23:18
Show Gist options
  • Save alejovdev/986d18cb87ea6f2644e78b3821c4ce31 to your computer and use it in GitHub Desktop.
Save alejovdev/986d18cb87ea6f2644e78b3821c4ce31 to your computer and use it in GitHub Desktop.
import React, { useState, useEffect } from "react";
import { firestore } from "./firebase";
function App() {
const [title, setTitle] = useState(null);
const [lang, setLang] = useState("en");
useEffect(() => getTitle(), []);
const getTitle = async () => {
let res = await firestore
.collection("translations")
.doc("title")
.get();
setTitle(res.data().translated);
};
return (
<div className="app">
<header className="title">{title !== null && title[lang]}</header>
<select
name="langSelect"
id="langSelect"
onChange={e => setLang(e.target.value)}
>
<option value="en">English</option>
<option value="es">Español</option>
<option value="fr">Français</option>
</select>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment