Function useEvent

  • Pick a value from an event

    Example

    const MyComponent = () => {
    const key = useEvent({
    eventName: "keydown",
    getValue: event => event.key,
    initialState: ""
    });

    return <div>Last used key was {key}</div>;
    }

    Type Parameters

    • EventName extends string | number | symbol

    • Event

    • Value

    • Target extends Window | HTMLElement | MediaQueryList = Window

    Parameters

    • __namedParameters: {
          eventName: EventName;
          getValue: ((event) => Value);
          initialState: StateInitializer<Value>;
          target?: Target;
      }
      • eventName: EventName

        name of the event

      • getValue: ((event) => Value)
          • (event): Value
          • function that receives the event and should return the value you are interested in

            Parameters

            • event: Event

            Returns Value

      • initialState: StateInitializer<Value>

        initial state or function that returns initial state

      • Optional target?: Target

        event target, defaults to window

    Returns Value

Generated using TypeDoc