- Progressive Web Apps with React
- Scott Domes
- 214字
- 2021-07-08 09:36:19
Splitting up our app
To organize our app a bit better (and to do some magic in the next section), let’s move our JSX into a separate file from our ReactDOM.render. This will ensure good separation of concerns throughout our file structure.
Next to index.js, in our src folder, create a file called App.js. Inside, we’ll just make a function called App, which returns our JSX:
import React from 'react';
const App = () => {
return <h1>Hello from React!!</h1>
};
export default App;
Note the export statement at the bottom; this means when we import our file, we’ll automatically get this function as the default import. We'll see an example of non-default imports down the line, which will make this clearer.
If we jump back to index.js, we can now import App from './App’. Then, we render it, as shown:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App'
ReactDOM.render(<App />, document.getElementById('root'));
Note that we are using it just like an HTML (or rather, JSX) tag. We’ll talk more about why in the coming chapters; for now, the important thing is that our app is a bit more organized, with our view logic (the JSX) separate from the render logic (ReactDOM.render).
- 大學計算機基礎(第二版)
- 復雜軟件設計之道:領域驅動設計全面解析與實戰
- Rust編程從入門到實戰
- Python高級編程
- Java Web基礎與實例教程
- Hands-On Functional Programming with TypeScript
- 計算機應用基礎實踐教程
- Oracle GoldenGate 12c Implementer's Guide
- Hands-On Neural Network Programming with C#
- 動手打造深度學習框架
- Java Web從入門到精通(第2版)
- 程序員的成長課
- Deep Learning for Natural Language Processing
- Python編程快速上手2
- Android 5從入門到精通