more comprehensive button click example
This commit is contained in:
@@ -23,22 +23,23 @@ function Counter() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `onClick` callback receives an `event` object. It includes some information, such as the user who clicked the button, and a function for creating new replies in response.
|
The `onClick` callback receives an `event` object. It includes some information, such as the user who clicked the button, and functions for creating new replies in response. These functions return message instances.
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
import { Button } from "reacord"
|
import { Button } from "reacord"
|
||||||
|
|
||||||
function TheButton() {
|
function TheButton() {
|
||||||
return (
|
function handleClick(event) {
|
||||||
<Button
|
const name = event.guild.member.displayName || event.user.username
|
||||||
label="click me i dare you"
|
|
||||||
onClick={(event) => {
|
const publicReply = event.reply(`${name} clicked the button. wow`)
|
||||||
const name = event.guild.member.displayName || event.user.username
|
setTimeout(() => publicReply.destroy(), 3000)
|
||||||
event.reply(`${name} clicked the button. wow`)
|
|
||||||
event.ephemeralReply("good job, you clicked it")
|
const privateReply = event.ephemeralReply("good job, you clicked it")
|
||||||
}}
|
privateReply.deactivate() // we don't need to listen to updates on this
|
||||||
/>
|
}
|
||||||
)
|
|
||||||
|
return <Button label="click me i dare you" onClick={handleClick} />
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user