import React from 'react';
const Hi = () => {
return (
<div>
<h1>hi</h1>
</div>
);
};
export default Hi;
import React from 'react';
import Hi from './Hi'
function display(){
return <Hi/>
}
const Main = () => {
return (
<div>
<button onClick={display}>отобразить</button>
</div>
);
};
export default Main;
import React, { useState } from 'react';
import Hi from './Hi'
function display(){
return <Hi/>
}
export const Main = () => {
const [isHiVisible, setHiVisible] = useState(false);
const onClick = () => {
setHiVisible((prev) => !prev);
}
return (
<div>
<button onClick={onClick}>отобразить</button>
{isHiVisible &&
<Hi/>
}
</div>
);
};