3 回答

TA貢獻1906條經驗 獲得超10個贊
我知道你想用 React 創建一個簡單的應用程序。我建議你先讀一 https://kentcdodds.com/blog/how-to-react,然后再讀這個:https://reactjs.org/tutorial/tutorial.html
可以通過在開始時導入腳本來創建 react 應用程序,但這不是構建 react 應用程序的推薦方法。
完成上述帖子后,請在您選擇的平臺上找到您選擇的好教程,無論是基于博客還是基于視頻。我可以舉出一些像udemy,前端大師,復數視覺,還有更多。

TA貢獻1936條經驗 獲得超7個贊
看看 ReactJS 網站。
你應該使用 Node 包管理器創建 React 應用程序 npx create-react-app appName
或者應該將反應腳本鏈接到您的html
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
也不能重新定義文檔對象。這將引用您的網頁,您可以使用文檔對象訪問元素或 DOM(文檔對象模型)。

TA貢獻2080條經驗 獲得超4個贊
根據 https://reactjs.org/docs/add-react-to-a-website.html,您需要在導入腳本之前將以下兩行添加到HTML文件中:
<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>
我不確定模塊加載是否會按照你想要的方式工作,而不使用像Create React App這樣的東西。您可以刪除導入語句,并且仍然可以在腳本中引用 React 和 ReactDOM。
例如:
'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
);
});
添加回答
舉報