Vev Help Center
Search…
useEditorState hook
Detect when the user interacts with your widget in editor mode.
For better widget usability, consider changing the state of your widget depending on which mode the user is in. For example, play a video when in preview mode, but stop it when in editor mode. Or, if the user is changing the background color of a hidden dropdown in your widget, reveal that dropdown when its background colour property is being changed.
useEditorState() returns the following:
  • disabled: boolean - true when in editor mode, false when in preview mode.
  • rule: string - tells which CSS rule the user is editing. Sets to β€˜host’ when no rule is being edited .
  • selected: boolean - true when widget is selected in editor mode.

Example

1
import { useEditorState } from 'vev';
2
import { useState, useEffect, useRef } from 'react';
3
​
4
export default function ({ url }: Props) {
5
const {disabled} = useEditorState();
6
const videoReference = useRef<HTMLVideoElement>(null);
7
8
// this function runs on every value change of 'disabled'
9
useEffect(() => {
10
//If disabled pause video
11
if (disabled) {
12
videoReference.current.pause();
13
} else {
14
videoReference.current.play();
15
}
16
}, disabled);
17
18
return <video className="video fill" src={url} ref={videoReference} />
19
}
Copied!
Copy link
Contents
Example