--- tags: 110-2 --- # 2/25 部課:React Introduction ## Installation: ### Create a react project: [Get Started](https://create-react-app.dev/docs/getting-started/) ```js= # npm install -g create-react-app npx create-react-app my-app cd my-app npm start ``` ```js= # 如果遇到 error: npm cache clean --force ``` #### 建完的檔案架構: <img src="https://i.imgur.com/BQXqhR1.png" style="width:40%"/> #### How to run ```javascript= npm start ``` ## React Docs [Main Concept](https://reactjs.org/docs/hello-world.html) ### Keyword Explanation 1. JSX 2. DOMElement 3. Components 4. State 5. LifeCycle ## Let's give it a try !!! https://reactjs.org/tutorial/tutorial.html ```jsx= import React from "react"; class Square extends React.Component { render() { return ( <button className="square"> {/* TODO */} </button> ); } } class Board extends React.Component { renderSquare(i) { return <Square />; } render() { const status = 'Next player: X'; return ( <div> <div className="status">{status}</div> <div className="board-row"> {this.renderSquare(0)} {this.renderSquare(1)} {this.renderSquare(2)} </div> <div className="board-row"> {this.renderSquare(3)} {this.renderSquare(4)} {this.renderSquare(5)} </div> <div className="board-row"> {this.renderSquare(6)} {this.renderSquare(7)} {this.renderSquare(8)} </div> </div> ); } } class Game extends React.Component { render() { return ( <div className="game"> <div className="game-board"> <Board /> </div> <div className="game-info"> <div>{/* status */}</div> <ol>{/* TODO */}</ol> </div> </div> ); } } export default Game; ```