diff --git a/packages/r3f/src/components/RefreshSnapshot.tsx b/packages/r3f/src/components/RefreshSnapshot.tsx index 2819313..17ede25 100644 --- a/packages/r3f/src/components/RefreshSnapshot.tsx +++ b/packages/r3f/src/components/RefreshSnapshot.tsx @@ -1,11 +1,11 @@ import React, {useEffect} from 'react' -import useRefreshSnapshot from './useRefreshSnapshot' +import {refreshSnapshot} from '../utils' /** * Putting this element in a suspense tree makes sure the snapshot editor * gets refreshed once the tree renders. * - * Alternatively you can use {@link useRefreshSnapshot} + * Alternatively you can use {@link refreshSnapshot} * * @example * Usage @@ -16,10 +16,11 @@ import useRefreshSnapshot from './useRefreshSnapshot' * * ``` */ -const RefreshSnapshot: React.FC<{}> = (props) => { - const refreshSnapshot = useRefreshSnapshot() +const RefreshSnapshot: React.FC<{}> = () => { useEffect(() => { - refreshSnapshot() + setTimeout(() => { + refreshSnapshot() + }) }, []) return <> } diff --git a/packages/r3f/src/components/useRefreshSnapshot.ts b/packages/r3f/src/components/useRefreshSnapshot.ts deleted file mode 100644 index d1af360..0000000 --- a/packages/r3f/src/components/useRefreshSnapshot.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {useCallback} from 'react' -import {useEditorStore} from '../store' - -/** - * Returns a function that can be called to refresh the snapshot in the snapshot editor. - */ -export default function useRefreshSnapshot() { - return useCallback(() => { - useEditorStore.getState().createSnapshot() - }, []) -} diff --git a/packages/r3f/src/index.tsx b/packages/r3f/src/index.tsx index 661807a..dee332e 100644 --- a/packages/r3f/src/index.tsx +++ b/packages/r3f/src/index.tsx @@ -4,5 +4,5 @@ export type {EditorHelperProps} from './components/EditorHelper' export {default as editable} from './components/editable' export type {EditableState, BindFunction} from './store' export {default as SheetProvider, useCurrentSheet} from './SheetProvider' -export {default as useRefreshSnapshot} from './components/useRefreshSnapshot' +export {refreshSnapshot} from './utils' export {default as RefreshSnapshot} from './components/RefreshSnapshot' diff --git a/packages/r3f/src/utils.ts b/packages/r3f/src/utils.ts new file mode 100644 index 0000000..619bd2d --- /dev/null +++ b/packages/r3f/src/utils.ts @@ -0,0 +1,3 @@ +import {useEditorStore} from './store' + +export const refreshSnapshot = useEditorStore.getState().createSnapshot