Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 842 Bytes

Readme.md

File metadata and controls

32 lines (22 loc) · 842 Bytes

BackButton

React component for Telegram Web Apps (TWA) Back Button.

Installation

npm i @twa-dev/sdk

Motivation

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

const BackButton = window.Telegram.WebApp.BackButton;

BackButton.show();
BackButton.onClick(() => window.history.back());

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

This package exports React component that wraps TWA BackButton SDK:

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

<BackButton onClick={() => window.history.back()} />

Demo

@BackButtonDemoBot

Codesandbox