Skip to content

Commit c62a668

Browse files
authored
fix: config issues (#1041)
1 parent cf41aed commit c62a668

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/@dcl/inspector/src/components/EntityInspector/SmartItemBasicView/SmartItemBasicView.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useCallback, useMemo } from 'react'
22
import { BsFillLightningChargeFill as SmartItemIcon } from 'react-icons/bs'
33
import { withSdk } from '../../../hoc/withSdk'
4-
import { useHasComponent } from '../../../hooks/sdk/useHasComponent'
54
import { ConfigComponent } from '../../../lib/sdk/components'
65
import { Container } from '../../Container'
76
import { NftView } from './NftView'
@@ -17,7 +16,6 @@ import './SmartItemBasicView.css'
1716

1817
const SmartItemBasicView = withSdk<Props>(({ sdk, entity }) => {
1918
const { Config } = sdk.components
20-
const hasConfig = useHasComponent(entity, Config)
2119

2220
const renderField = useCallback(
2321
(field: ConfigComponent['fields'][0], idx: number) => {
@@ -52,12 +50,12 @@ const SmartItemBasicView = withSdk<Props>(({ sdk, entity }) => {
5250
)
5351
}, [])
5452

55-
if (!hasConfig) return null
56-
5753
const config = useMemo(() => {
58-
return Config.get(entity)
54+
return Config.getOrNull(entity)
5955
}, [entity])
6056

57+
if (!config) return null
58+
6159
return (
6260
<Container
6361
label={config.componentName}

packages/@dcl/inspector/src/hooks/sdk/useHasComponent.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Entity } from '@dcl/ecs'
2-
import { useState } from 'react'
2+
import { useEffect, useState } from 'react'
33

44
import { Component } from '../../lib/sdk/components'
55
import { useChange } from './useChange'
@@ -13,5 +13,9 @@ export const useHasComponent = (entity: Entity, component: Component) => {
1313
}
1414
})
1515

16+
useEffect(() => {
17+
setHasComponent(component.has(entity))
18+
}, [entity, component])
19+
1620
return hasComponent
1721
}

0 commit comments

Comments
 (0)