- 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).
- Java程序設計(慕課版)
- Apache ZooKeeper Essentials
- Photoshop智能手機APP UI設計之道
- 零基礎玩轉區塊鏈
- Android NDK Beginner’s Guide
- Java深入解析:透析Java本質的36個話題
- Unity Shader入門精要
- 網絡爬蟲原理與實踐:基于C#語言
- Ext JS 4 Web Application Development Cookbook
- Java EE 7 Performance Tuning and Optimization
- Apache Mahout Clustering Designs
- Visual C#.NET程序設計
- Scala Reactive Programming
- IBM Cognos Business Intelligence 10.1 Dashboarding cookbook
- 代替VBA!用Python輕松實現Excel編程