function App() {
return(
<div>
<h3>Hello!</h3>
<div> // JSX
)
}
import "./styles.css";
import React, { useState } from "react";
import Field from "./components/field";
import Translate from "./components/translate";
import Languages from "./components/languages";
export default function App() {
const [language, setLanguage] = useState("es");
const [text, setText] = useState("");
return (
<div>
<Field onChange={setText} />
<Languages language={language} onLanguageChange={setLanguage} />
<hr />
<Translate text={text} language={language} />
</div>
);
}
React Startup Process (All inside the index.html file)
- (1) Find the div with id of 'root' in the DOM
- (2) Tell React to take control of that element
- (3) Tell React to get JSX from the App component, turn it into HTML, and show it in the root.
<!-- index.html -->
<html>
<head></head>
<body>
<div id="root> <!-- (1) --> </div>
</body>
</html>
// bundle.js
const rootElement = document.getElementById('root')
const root = createRoot(rootElement)
root.render(<App />)
Our app had three pieces of data that changed
- The text the user typed into the text input
- Language the user wanted to translate text to
- The result of the translation
import "./styles.css";
import React, { useState } from "react";
import Field from "./components/field";
import Translate from "./components/translate";
import Languages from "./components/languages";
export default function App() {
const [language, setLanguage] = useState("es");
const [text, setText] = useState("");
return (
<div>
<Field onChange={setText} />
<Languages language={language} onLanguageChange={setLanguage} />
<hr />
<Translate text={text} language={language} />
</div>
);
}
Text from input & Selected Language
↓
[Translated Component]
-Did the text or language change? → If so, make a network request with the new text/language → Google Translate API