我正在尝试带有反应16.7的钩子的功能组件,有一个错误:
SRC /组件/页脚/ index.js
function Footer() { const [selectedTab,setSelectedTab] = useState('redTab'); const [hidden,setHidden] = useState(false); const [fullScreen,setFullScreen] = useState(false); //... }
的package.json
我该怎么办?
确保将react-dom升级到16.7.0-alpha.0.
原文链接:https://www.f2er.com/react/300668.html的package.json
{ "dependencies": { "react": "16.7.0-alpha.0","react-dom" "16.7.0-alpha.0",... },... }
也许你只是在没有安装新版本的情况下碰撞了package.json中的版本. You can remove node_modules
and install again.
npm ci
例
const { useState } = React; function Footer() { const [selectedTab,setFullScreen] = useState(false); return ( <div> <button onClick={() => setSelectedTab('blueTab')}>{selectedTab}</button> <button onClick={() => setHidden(isHidden => !isHidden)}> {hidden ? 'hidden' : 'visible'} </button> <button onClick={() => setFullScreen(isFullScreen => !isFullScreen)}> {fullScreen ? 'fullscreen' : 'windowed'} </button> </div> ); } ReactDOM.render( <Footer />,document.getElementById('root') );
<script src="https://unpkg.com/react@16.7.0-alpha.0/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@16.7.0-alpha.0/umd/react-dom.development.js"></script> <div id="root"></div>