Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.03 KB

Readme.md

File metadata and controls

43 lines (32 loc) · 1.03 KB

MainButton

React component for Telegram Web Apps (TWA) MainButton.

Installation

npm i @twa-dev/sdk

Motivation

TWA SDK contains an interface that controls MainButton. It's written in imperative way:

const MainButton = window.Telegram.WebApp.MainButton;

MainButton.setText('Submit');
MainButton.show();
MainButton.onClick(() => alert('submitted'));

It's not the best way to write code, especially if you use libraries like React.

This package exports React component that wraps TWA MainButton SDK:

import { MainButton } from '@twa-dev/sdk/react';

<MainButton text="Submit" onClick={() => alert('submitted')} />

Demo

@BottomButtonBot

Codesandbox

Props

Naming is pretty straight forward and corresponds SDK props and methods:

  • text
  • color
  • textColor
  • disabled
  • progress
  • onClick
  • hasShineEffect