Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/useTweaks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useState, useLayoutEffect, useRef } from 'react'
import { useState, useRef } from 'react'
import Tweakpane from 'tweakpane'

import { getData, buildPane } from './data'
import { Schema, Settings, UseTweaksValues } from './types'
import { useIsomorphicLayoutEffect } from './utils'

let ROOTPANE: Tweakpane | undefined

Expand All @@ -18,7 +19,7 @@ export function useTweaks<T extends Schema>(

const [data, set] = useState(() => getData(_schema.current, _rootKey))

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
ROOTPANE = ROOTPANE || new Tweakpane({ ..._settings, container: _settings.current?.container?.current! })
const isRoot = _name === undefined
const _pane = _name ? ROOTPANE.addFolder({ title: _name }) : ROOTPANE
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { useEffect, useLayoutEffect } from 'react'

export function uuid(): string {
return `${Math.floor((new Date().getTime() * Math.random()) / 1000)}`
}

export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect