Add useInstance (#6)
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](/guides/sending-messages) 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 />)
|
||||
```
|
||||
@@ -25,7 +25,7 @@
|
||||
"react-dom": "^17.0.2",
|
||||
"remix": "^1.1.1",
|
||||
"remix-tailwind": "^0.2.1",
|
||||
"tailwindcss": "^3.0.12"
|
||||
"tailwindcss": "^3.0.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@remix-run/dev": "^1.1.1",
|
||||
@@ -39,7 +39,7 @@
|
||||
"concurrently": "^7.0.0",
|
||||
"cypress": "^9.2.1",
|
||||
"execa": "^6.0.0",
|
||||
"rehype-prism-plus": "^1.3.0",
|
||||
"rehype-prism-plus": "^1.3.1",
|
||||
"typedoc": "^0.22.10",
|
||||
"typescript": "^4.5.4",
|
||||
"wait-on": "^6.0.0"
|
||||
|
||||
Reference in New Issue
Block a user