Merge pull request #145

* Fix RefreshSnapshot component and make useRefreshSnapshot not a hook,…
This commit is contained in:
Andrew Prifer 2022-05-04 17:10:42 +02:00 committed by GitHub
parent fceb1eb60a
commit c1e515a13f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 17 deletions

View file

@ -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'
* </Suspense>
* ```
*/
const RefreshSnapshot: React.FC<{}> = (props) => {
const refreshSnapshot = useRefreshSnapshot()
const RefreshSnapshot: React.FC<{}> = () => {
useEffect(() => {
setTimeout(() => {
refreshSnapshot()
})
}, [])
return <></>
}

View file

@ -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()
}, [])
}

View file

@ -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'

View file

@ -0,0 +1,3 @@
import {useEditorStore} from './store'
export const refreshSnapshot = useEditorStore.getState().createSnapshot