Skip to content

useZoomFactor

Category
Export Size
408 B
Package
@reause/electron
Last Changed
5 days ago

Reactive WebFrame zoom factor.

Demo

Usage

tsx
import { 
useZoomFactor
} from '@reause/electron'
// enable nodeIntegration if you don't provide webFrame explicitly // see: https://www.electronjs.org/docs/api/webview-tag#nodeintegration // tuple result will return const [
factor
,
setFactor
] =
useZoomFactor
()
console
.
log
(
factor
) // print current zoom factor
setFactor
(2) // change current zoom factor

Set initial zoom factor immediately

tsx
import { 
useZoomFactor
} from '@reause/electron'
const [
factor
] =
useZoomFactor
(2)

Pass a state value and the factor will be updated when the source value changes

tsx
import { 
useZoomFactor
} from '@reause/electron'
import {
useState
} from 'react'
const [
factor
,
setFactor
] =
useState
(1)
useZoomFactor
(
factor
) // zoom factor will match with the state
setFactor
(2) // zoom factor will change

Type Declarations

ts
export type ZoomFactorSetter = (value: number) => void

export function useZoomFactor(factor?: number): [
    number,
    ZoomFactorSetter
]

export function useZoomFactor(webFrame: WebFrame, factor?: number): [
    number,
    ZoomFactorSetter
]

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
363b1 - fix(electron): resolve useZoomFactor audit findings (#811)
b7274 - fix(electron): resolve useZoomLevel audit findings (#812)
1c968 - feat(electron): add useZoomFactor, useZoomLevel (#256, #257)

Released under the MIT License. v0.1.8