const { useState } = React;
function App() {
return (
)
}
function Container() {
const setPopupVisible = () => {
console.log('Popup should appear')
}
return (
- Item 1
- Item 2
)
}
function Popup() {
const [visible, setVisible] = useState(false)
return (
visible ?
Popup
: ''
)
}
ReactDOM.render( , document.querySelector("#app"))
function Container() {
const [isVisible, setIsVisible] = useState(false);
const setPopupVisible = () => {
console.log('Popup should appear')
setIsVisible(true);
}
return (
- Item 1
- Item 2
)
}
コンポーネントは次のようになりPopupます。useEffect小道具の変更を検出するために使用
function Popup({visible}) {
const [visible, setVisible] = useState(false);
useEffect(()=>{
setVisible(visible);
}, [visible]);
return (
visible ?
Popup
: ''
)
}