React前端
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # [第02堂] 安裝React環境 ## Node.js >一個JavaScript 執行環境(run-time environment):[傳送門](https://nodejs.org/en/) (下載左邊LTS版本) * LTS 版本:表示這個版本會由官方長期維護,通常會持續至少 30 個月以上的問題修正。 * Current 版本:當前最新的版本,雖然裡面可能會有新功能,但是這些功能最後不見得會留下來。 ![image](https://hackmd.io/_uploads/HyO4x4Mpp.png) ## NVM >Node Version Manger,**Node 的版本管理器**,管理、切換Node版本。 >下載nvm-setup.zip檔案:[傳送門](https://github.com/coreybutler/nvm-windows/releases/tag/1.1.7) ### 常用指令 * **nvm ls**:列出所有已安裝的node版本,前面有標`*`是目前使用的版本 * **nvm install `<version>`**:安裝某個版本的 node * **nvm uninstall `<version>`**:解除安裝指定版本 * **nvm --version**:查看nvm版本 * **nvm use `<version>`**:切換node版本 ``` $ nvm ls 18.12.1 * 16.13.1 (Currently using 64-bit executable) 12.14.0 ``` ## NPM >Node Package Manager,**Node 的套件管理器**,安裝Node.js的時候會一起安裝,能下載和管理各種套件。 ### 常用指令 * **npm install**:尋找該資料夾裡面的package.json去下載裡面定義好的所有套件 * **npm init**:專案初始化讀取package.json的資訊,[傳送門](https://ithelp.ithome.com.tw/articles/10191682) * **npm start**:本地運行專案 * **npm run build**:將專案打包成webpack ## NPX >和NPM一樣是套件管理工具,不過是以暫存的方式使用套件,用完就刪。 更詳細解答:[傳送門](https://ithelp.ithome.com.tw/articles/10234240?sc=iThelpR) ### 常用指令 * **npx create-react-app `<name>`**:建立一個React專案,並把所有會用到的工具套件都安裝完畢 :::info :bulb: React 環境建置可分為兩種 * **自己從頭開始做**: 使用 React + Webpack 打包 + Bable 編譯 + Webpack Dev Server * **使用現成的套件**: create-react-app,由 React 官方提供,是一套CLI(Command Line Interface)工具 ::: ## 起一個新的專案 * **step 1** ``` $ node -v ``` 若出現找不到指令,就是沒安裝成功。 * **step 2** ``` $ npx create-react-app my-app ``` * **step 3** ``` $ cd /my-app ``` 可以透過cd ..、ls等指令找到專案 * **step 4** ``` $ npm start ``` ### 檔案目錄結構 | ---- **/node_modules** 負責用來存放經由 npm 安裝過後的套件 | ---- **/public** 靜態網頁 | ---- **/src** 專案中主要的檔案都會放置在此資料夾下,其中 index.js 是整個專案的程式進入點, App.js 是 React 建立專案預設的元件。 | ---- **.gitignore** 忽略不上傳git的檔案 (ex:.env、package-lock.json、node_modules)。 | ---- **package-lock.json** 在npm install時後生成一份文件,紀錄當前狀態下安裝的各個npm package的具體來源和版本號。 | ---- **package.json** 記錄所有安裝的套件與版本,用於專案設定與可以一次安裝多項套件,並且解決相依性問題。 | ---- **README.md** index.js 為 React 專案啟動時的進入點,會把放在ReactDOM.render裡面的程式渲染在html檔裡面的root標籤內,一般會將App.js頁面元件放置於此進行渲染。 * 渲染 在網頁載入時,將React 元件轉換成網頁內容的過程。 ## 常用套件 * [lodash](https://lodash.com/) * [moment](https://momentjs.com/) * [Ant Design(ANTD)](https://ant.design/components/overview/) * [Mantine](https://mantine.dev/) * [ECHARTS](https://echarts.apache.org/zh/index.html) * [SweetAlert2](https://sweetalert2.github.io/#examples) ### ReactDOM.render >是React的程式進入點,用來將 Virtual DOM 轉換成為真實的DOM。 把要渲染的內容丟入ReactDOM -> ReactDOM整理要渲染的內容 -> 對原始綁定的div在DOM上的位置做渲染 -> 完成畫面渲染 寫法: ReactDOM.render(要顯示的 React Element, 要顯示到哪個 HTML DOM element ) ```javascript= ReactDOM.render(<App />, document.getElementById("root")); ``` ```javascript= ## React v18 const root = ReactDOM.createRoot(document.getElementById('root')); root.render( <React.StrictMode> <App /> </React.StrictMode> ); ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully