UNPKG

@wareme/smooth-scrolling

Version:

High performance smooth scrolling for Dark applications

32 lines (23 loc) 635 B
import { useState, useEffect } from '@dark-engine/core' import { EventEmitter } from '@wareme/event-emitter' export class Store { state eventEmitter constructor(state) { this.state = state this.eventEmitter = new EventEmitter() } set = (state) => { this.state = state this.eventEmitter.emit(this.state) } on = (callback) => this.eventEmitter.on(callback) get = () => this.state } export function useStore (store) { const [storeState, setStoreState] = useState(store.get()) useEffect(() => { return store.on((newState) => setStoreState(newState)) }, [storeState]) return storeState }