button guide
This commit is contained in:
@@ -6,4 +6,40 @@ description: Using button components
|
||||
|
||||
# Buttons
|
||||
|
||||
todo
|
||||
Use the `<Button />` component to create a message with a button, and use the `onClick` callback to respond to button clicks.
|
||||
|
||||
```jsx
|
||||
import { Button } from "reacord"
|
||||
|
||||
function Counter() {
|
||||
const [count, setCount] = useState(0)
|
||||
|
||||
return (
|
||||
<>
|
||||
You've clicked the button {count} times.
|
||||
<Button label="+1" onClick={() => setCount(count + 1)} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
```jsx
|
||||
import { Button } from "reacord"
|
||||
|
||||
function TheButton() {
|
||||
return (
|
||||
<Button
|
||||
label="click me i dare you"
|
||||
onClick={(event) => {
|
||||
const name = event.guild.member.displayName || event.user.username
|
||||
event.reply(`${name} clicked the button. wow`)
|
||||
event.ephemeralReply("good job, you clicked it")
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
See the [API reference](/api) for more information.
|
||||
|
||||
Reference in New Issue
Block a user