Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

overwolf-hooks

1.0.1 • Public • Published

Overwolf Hooks

Custom hooks to help use overwolf api with the new react hooks technology.

NPM JavaScript Style Guide

Install

npm install --save overwolf-hooks

How to use

Hooks

  1. useWindow.ts
import React from "react";
import { useWindow } from 'overwolf-hooks'
 
const Panel:FC = ()=>{
const [desktopWindow] = useWindow("desktop");
 
return <>
          <p>Desktop Window</p>
          <button onClick={()=> desktopWindow?.minimize()}>Minimize</button>
          <button onClick={()=> desktopWindow?.restore()}>Restore</button>
          <button onClick={()=> desktopWindow?.maximize()}>Maximize</button>
          <button onClick={()=> desktopWindow?.close()}>Close</button>
        </>
}
  1. useDrag.ts
import React,{ useCallback } from "react";
import { useDrag, useWindow } from 'overwolf-hooks'
 
const Header:FC = ()=>{
const [desktopWindow] = useWindow("desktop");
const { onDragStart, onMouseMove, setCurrentWindowID } = useDrag(null);
 
const updateDragWindow = useCallback(() => {
  if (desktopWindow?.id) setCurrentWindowID(desktopWindow.id);
}, [desktopWindow]);
 
return <header onMouseDown={event => onDragStart(event)} onMouseMove={event => onMouseMove(event)}>
          Header Text
        </header>
}
  1. useGameEventProvider.ts
import React,{ useEffect } from "react";
import { useGameEventProvider } from 'overwolf-hooks'
 
const Overlay:FC = ()=>{
const [{ event, info }, setGameFeatures] = useGameEventProvider<
    GameExample.Info,
    GameExample.Event
  >();
 
  useEffect(() => {
    console.info("event", event); // or use https://github.com/AlbericoD/overwolf-modern-react-boilerplate#-remote-redux-debug
  }, [event]);
 
  useEffect(() => {
    console.info("info", info); // or use https://github.com/AlbericoD/overwolf-modern-react-boilerplate#-remote-redux-debug
  }, [info]);
 
return <p>Overlay Window</p>
 
}
  1. useRunningGame.ts
import React,{ useEffect } from "react";
import { useGameEventProvider } from 'overwolf-hooks'
 
const Alert:FC = ()=>{
  const [currentGame] = useRunningGame();
 
  useEffect(() => {
    console.info("currentGame", currentGame);
  }, [currentGame]);
 
return <p>Alert Window</p>
 
}

License

MIT © AlbericoD

Keywords

none

Install

npm i overwolf-hooks

DownloadsWeekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

1.56 MB

Total Files

48

Last publish

Collaborators

  • avatar