use key props to reload workspace when upload new file

This commit is contained in:
Qing
2022-06-28 22:25:52 +08:00
parent 689d61968c
commit 0daa27e11a
5 changed files with 27 additions and 21 deletions

View File

@@ -1,6 +1,7 @@
import React, { useEffect } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import { useKeyPressEvent } from 'react-use'
import { useRecoilState } from 'recoil'
import { nanoid } from 'nanoid'
import useInputImage from './hooks/useInputImage'
import LandingPage from './components/LandingPage/LandingPage'
import { themeState } from './components/Header/ThemeChanger'
@@ -33,10 +34,18 @@ function App() {
document.body.setAttribute('data-theme', theme)
}, [theme])
const getWorkspaceKey = useCallback(() => {
return nanoid()
}, [file])
return (
<div className="lama-cleaner">
<Header />
{file ? <Workspace file={file} /> : <LandingPage />}
{file ? (
<Workspace file={file} key={getWorkspaceKey()} />
) : (
<LandingPage />
)}
</div>
)
}