@vkontakte/vk-bridge-react
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

VK Bridge React

React hooks for VK Bridge.

In addition, the library provides other helper functions.

Usage

npm install @vkontakte/vk-bridge @vkontakte/vk-bridge-react
import { useInsets, runTapticImpactOccurred } from '@vkontakte/vk-bridge-react';

// Sends event to client
const App = () => {
  const insets = useInsets();

  const handleClick = () => {
    runTapticImpactOccurred();
  };

  return (
    <div style={{ paddingTop: insets?.top }}>
      <button onClick={handleClick}>Touch me and feel</button>
    </div>
  );
};

Hooks

Name Return type Description
useAppearance()
type UseAppearance = AppearanceType | null;

Hook listens to update the appearance property of the VKWebAppUpdateConfig event. It dispatches the VKWebAppGetConfig event on first initialization.

Note: hook works only for vkBridge.isEmbedded() mode.

useAdaptivity()
interface UseAdaptivity {
  type: null | AdaptivityType;
  viewportWidth: number;
  viewportHeight: number;
}
Hook listens to update the adaptivity property of the VKWebAppUpdateConfig event.
useInsets()
type UseInsets = {
  top: number;
  right: number;
  bottom: number;
  left: number;
} | null;

Hook listens to update the insets property of the VKWebAppUpdateConfig event.

Note: when the virtual keyboard is visible, inset of bottom corresponds to 0.

Helpers

Name Return type Description
runTapticImpactOccurred boolean Function dispatches VKWebAppTapticImpactOccurred event if it is support (will return true).

Dependents (0)

Package Sidebar

Install

npm i @vkontakte/vk-bridge-react

Weekly Downloads

257

Version

1.0.1

License

MIT

Unpacked Size

33.4 kB

Total Files

14

Last publish

Collaborators

  • sklv_r
  • vitaliy.podlubnyak
  • adeltsareva
  • v.kirichenko
  • vkarelin
  • gbowsky
  • pa.koshkin
  • vkcom
  • k.egor.smirnov
  • vkcom-publisher
  • terdenan
  • captain__bamboo