我是 React 的新手,每次单击按钮时我都试图更改元素的值。我在网上看,我认为它应该可以工作,但由于某种原因它不是!提前致谢
import React from 'react';
import ReactDOM from 'react-dom';
const App = () => {
let showDetails = false;
const visabillty = () => {
showDetails = !showDetails;
};
return (
<div style={{textAlign: 'center', margin: '40px'}}>
<h1>Visailty Project</h1>
<button onClick={visabillty}>
{showDetails ? 'show Details' : 'hide Deatils '}
</button>
<h1> {showDetails ? 'hello' : 'buy'}</h1>
</div>
);
};
ReactDOM.render(<App />, document.getElementById('root'));
Run Code Online (Sandbox Code Playgroud)