3 回答

TA贡献1906条经验 获得超10个赞
我知道你想用 React 创建一个简单的应用程序。我建议你先读一 https://kentcdodds.com/blog/how-to-react,然后再读这个:https://reactjs.org/tutorial/tutorial.html
可以通过在开始时导入脚本来创建 react 应用程序,但这不是构建 react 应用程序的推荐方法。
完成上述帖子后,请在您选择的平台上找到您选择的好教程,无论是基于博客还是基于视频。我可以举出一些像udemy,前端大师,复数视觉,还有更多。

TA贡献1936条经验 获得超6个赞
看看 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
);
});
添加回答
举报