Skip to content

Instantly share code, notes, and snippets.

@topspinppy
Created July 15, 2020 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topspinppy/d53f48318fb9e1e5b21fc4f707cd9e03 to your computer and use it in GitHub Desktop.
Save topspinppy/d53f48318fb9e1e5b21fc4f707cd9e03 to your computer and use it in GitHub Desktop.
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