Skip to content

Commit

Permalink
fix: BugWithReusingSpace (#100)
Browse files Browse the repository at this point in the history
* feat: include id from props not config

* chore: changeset

* Update .changeset/funny-shirts-argue.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
bangarang and coderabbitai[bot] authored Apr 26, 2024
1 parent 8e3949f commit 1473f79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-shirts-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@flatfile/react': patch
---

Fixes bug with re-using spaces.
2 changes: 1 addition & 1 deletion apps/react/app/re-used-space/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ const App = () => {
</button>
</div>
<Space
id={SPACE_ID}
config={{
id: SPACE_ID,
metadata: {
sidebarConfig: {
showSidebar: true,
Expand Down
9 changes: 6 additions & 3 deletions packages/react/src/components/Space.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useDeepCompareEffect } from '../utils/useDeepCompareEffect'

type SpaceProps = {
id?: string
config: Flatfile.SpaceConfig
config?: Flatfile.SpaceConfig
children?: React.ReactNode
}

Expand Down Expand Up @@ -33,11 +33,14 @@ type SpaceProps = {
*/

export const Space = (props: SpaceProps) => {
const { config, children } = props
const { config, id, children } = props
const { updateSpace } = useContext(FlatfileContext)

const callback = useCallback(() => {
updateSpace(config)
updateSpace({
...(config || {}),
id,
})
}, [config, updateSpace])

useDeepCompareEffect(callback, [config])
Expand Down

0 comments on commit 1473f79

Please sign in to comment.