Code Monkey home page Code Monkey logo

react-telegram-web-app's People

Contributors

alexgoto avatar github-actions[bot] avatar vkruglikov avatar xsa-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-telegram-web-app's Issues

disabled MainButton still has normal appearance

Package version: 2.1.4
React version: "^18.2.0"

Steps To Reproduce

  1. Render <MainButton disabled text='Update' onClick={()=> update()} />

The current behavior

Button still looks like active, but doesn't accept clicks.

The expected behavior

Button expected to look "disabled" (somehow grayed out, etc).

React Hook cannot be called in a class component

Hello
I have problem with useShowPopup() in a class

WARNING in [eslint]
src\components\Form.tsx
  Line 61:26:  React Hook "useShowPopup" cannot be called in a class component. React Hooks must be called in a React function component or a custom React Hook function  react-hooks/rules-of-hooks

Access window.navigator in twa?

I would like to know if it's possible to access window.navigator in a telegram mini web app (twa)?
If not, what it the reason? Is there a chance to extend it? Will there be more web APIs in the twa? If I would want to make pull requests to extend that for telegram, where is the repo for that?

suggestion

can you add a general hook (useWebApp for example) to get properties from window.Telegram.WebApp?
e.g platform, enableClosingConfirmation(), disableClosingConfirmation() etc...

Mainbutton and Backbutton not show in next.js

Package version: 2.1.4
React version: 18.2.0
Telegram.WebApp version:

Steps To Reproduce

  1. create a next.js app
  2. pnpm add @vkruglikov/react-telegram-web-app
  3. add Privoder and Mainbutton in app/page.tsx
"use client"
import {
  BackButton,
  MainButton,
  WebAppProvider,
} from "@vkruglikov/react-telegram-web-app";

export default function Page() {
  return (
    <WebAppProvider
      options={{
        smoothButtonsTransition: true,
      }}
    >
      <h1>Hello, Quest Page!</h1>
      <MainButton text="Continue with task" progress={true} />       
      <BackButton onClick={() => console.log("back")} />
    </WebAppProvider>
  );
}
  1. run pnpm dev && ngrok 3000
  2. update the webapp bot URL to ngrok provide
  3. click the bot URL and see the result.
    image

Link to code example:

The current behavior

The expected behavior

Add expand()

Addition of expand() which is a method that expands the Web App to the maximum available height.

Do you plan to work on this?

So that this could be plugged in as the default behaviour for the user when the interact with the TWA

useInitData doesn't work with nextjs

Exceptions throws when nextjs renders components on server and window.Telegram.WebApp is unavailable.

Code does not handle this situation:

const useInitData = (): readonly [InitDataUnsafe, InitData] => {
const WebApp = useWebApp();
return [WebApp!.initDataUnsafe, WebApp!.initData] as const;
};

For example, this code (useShowPopup) works fine, because handles situation with temporarily unavailable window:

const useShowPopup: () => ShowPopupFunction = () => {
const WebApp = useWebApp();
return useCallback(
params =>
new Promise((resolve, reject) => {
try {
WebApp?.showPopup?.(params, (buttonId: string) => {
resolve(buttonId);
});
} catch (e) {
reject(e);
}
}),
[WebApp],
);
};

I think we need do the same with useInitData. Or, simply, need to set undefined to initData and initDataUnsafe when window is unavailablle.

I can make PR if you accept

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.