add useInstance
This commit is contained in:
26
packages/website/app/routes/guides/use-instance.md
Normal file
26
packages/website/app/routes/guides/use-instance.md
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
meta:
|
||||
title: useInstance
|
||||
description: Using useInstance to get the current instance within a component
|
||||
---
|
||||
|
||||
# useInstance
|
||||
|
||||
You can use `useInstance` to get the current instance within a component. This can be used to let a component destroy or deactivate itself.
|
||||
|
||||
```jsx
|
||||
import { Button, useInstance } from "reacord"
|
||||
|
||||
function SelfDestruct() {
|
||||
const instance = useInstance()
|
||||
return (
|
||||
<Button
|
||||
style="danger"
|
||||
label="delete this"
|
||||
onClick={() => instance.destroy()}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
reacord.send(channelId, <SelfDestruct />)
|
||||
```
|
||||
Reference in New Issue
Block a user