---
# System prepended metadata

title: React 學習心得
tags: [JavaScript, js]

---

React 學習心得
===
###### tags: `JavaScript` `js`


body 新增程式碼
```htmlmixed=
<h2>Add React in One Minute</h2>
<p>This page demonstrates using React with no build tooling.</p>
<p>React is loaded as a script tag.</p>

<p>
  This is the first comment.
  <!-- We will put our React component inside this div. -->
  <div class="like_button_container" data-commentid="1"></div>
</p>

<p>
  This is the second comment.
  <!-- We will put our React component inside this div. -->
  <div class="like_button_container" data-commentid="2"></div>
</p>

<p>
  This is the third comment.
  <!-- We will put our React component inside this div. -->
  <div class="like_button_container" data-commentid="3"></div>
</p>

<!-- Load React. -->
<!-- Note: when deploying, replace "development.js" with "production.min.js". -->
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>

<!-- Load our React component. -->
<script src="index.js"></script>
```

新增 index.js
```javascript=
'use strict';

const e = React.createElement;

class LikeButton extends React.Component {
  constructor(props) {
    super(props);
    this.state = { liked: false };
  }

  render() {
    if (this.state.liked) {
      return 'You liked comment number ' + this.props.commentID;
    }

    return e(
      'button',
      { onClick: () => this.setState({ liked: true }) },
      'Like'
    );
  }
}

// Find all DOM containers, and render Like buttons into them.
document.querySelectorAll('.like_button_container')
  .forEach(domContainer => {
    // Read the comment ID from a data-* attribute.
    const commentID = parseInt(domContainer.dataset.commentid, 10);
    ReactDOM.render(
      e(LikeButton, { commentID: commentID }),
      domContainer
    );
  });

```
![](https://i.imgur.com/P05mCgS.png)




## 自學筆記
[java script 學習心得（vscode）](https://hackmd.io/@chiisen/rJ-Tqmfo8)
[Angular 學習心得](https://hackmd.io/@chiisen/SJLZQUph8)
[Vue 學習心得](https://hackmd.io/@chiisen/Bk4_zwphU)

## 參考資料
[【跟山地人学React系列教程】课00.5分钟快速入门React](https://www.youtube.com/watch?v=eYzbrroNv_E)
[React - Getting Started](https://reactjs.org/docs/getting-started.html)
點擊 Add React to a Website


