如果想使用React但不使用npm,可以通过以下步骤手动添加React到项目中:
下载React库文件:
js
文件夹,并将下载的React库文件保存到该文件夹中。下载React DOM库文件:
js
文件夹中保存下载的React DOM库文件。创建HTML文件:
index.html
。index.html
中添加以下代码:
React without npm
js
文件夹中创建一个app.js
文件。app.js
中编写React应用的代码,例如:const { useState } = React;
function App() {
const [count, setCount] = useState(0);
return (
React without npm
Count: {count}
);
}
ReactDOM.render( , document.getElementById('root'));
index.html
文件,即可看到React应用运行的效果。请注意,这种方法仅适用于简单的React应用,对于复杂的项目,建议使用npm来管理和构建React应用。