import AttributeMinHeight from './attributes/_minHeight.md'; import AttributeMaxHeight from './attributes/_maxHeight.md'; import AttributeMinWidth from './attributes/_minWidth.md'; import AttributeMaxWidth from './attributes/_maxWidth.md'; import AttributeGrow from './attributes/_grow.md'; import AttributeOnPress from './attributes/_onPress.md'; import AttributeWidth from './attributes/_width.mdx'; import AttributeHeight from './attributes/_height.mdx';
The <button> element creates an interactive button that users can click or tap.
Adds an icon to the button, specified by its string identifier.
Can be used with or without a text label.
Note: Buttons can only use the icons provided here (see icon). To use custom buttons you'll have to use use an image (instructions here)
An icon button
<button icon="home" />A button with a an icon and a label
<button icon="home">Label</button>A button with no icon
<button>Label</button>Determines the button size. Possible values:
small: 32pxmedium: 40px. The default if the attribute is not used.large: 48px
A small button
<button size="small">Label</button>Sets the button style. Possible values:
primarysecondary: The default if the attribute is not used.plainborderedmediadestructivecautionsuccess
A primary button
<button appearance="primary">Label</button>Disables the button if set to true, preventing interactions.
A disabled button button
<button disabled>Label</button>A disabled button button
<button disabled={true}>Label</button>A growing button
<button grow>Label</button><button onPress={() => console.log('world')}>Hello</button>A button that increments a counter
import { Devvit, useState } from '@devvit/public-api';
// addCustomPostType() is deprecated and will be unsupported. It will not work after June 30.
Devvit.addCustomPostType({
name: 'Say Hello',
render: (context) => {
const [votes, setCounter] = useState(0);
return (
<blocks>
<vstack alignment="center middle" height="100%" width="100%">
<button icon="upvote-outline" onPress={() => setCounter(votes + 1)}>
{votes}
</button>
</vstack>
</blocks>
);
},
});

