Created
July 15, 2020 16:54
-
-
Save topspinppy/d53f48318fb9e1e5b21fc4f707cd9e03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Noti = forwardRef(({ title, content, onClose }, ref) => { | |
const show = () => { | |
console.log(title, content) | |
} | |
useImperativeHandle(ref, () => { | |
return { | |
trigerNoti: () => { | |
show() | |
} | |
} | |
}, []) | |
return null | |
}) | |
export default function App() { | |
const notiRef = useRef() | |
return ( | |
<div className="App"> | |
<button onClick={() => { | |
notiRef.current && notiRef.current.trigerNoti() | |
}}>Show noti</button> | |
<Noti show={isShow} ref={notiRef} content='Content' title='Title' /> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment