Skip to content

Commit

Permalink
fix: config issues (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
cazala authored Nov 29, 2024
1 parent cf41aed commit c62a668
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useCallback, useMemo } from 'react'
import { BsFillLightningChargeFill as SmartItemIcon } from 'react-icons/bs'
import { withSdk } from '../../../hoc/withSdk'
import { useHasComponent } from '../../../hooks/sdk/useHasComponent'
import { ConfigComponent } from '../../../lib/sdk/components'
import { Container } from '../../Container'
import { NftView } from './NftView'
Expand All @@ -17,7 +16,6 @@ import './SmartItemBasicView.css'

const SmartItemBasicView = withSdk<Props>(({ sdk, entity }) => {
const { Config } = sdk.components
const hasConfig = useHasComponent(entity, Config)

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

if (!hasConfig) return null

const config = useMemo(() => {
return Config.get(entity)
return Config.getOrNull(entity)
}, [entity])

if (!config) return null

return (
<Container
label={config.componentName}
Expand Down
6 changes: 5 additions & 1 deletion packages/@dcl/inspector/src/hooks/sdk/useHasComponent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity } from '@dcl/ecs'
import { useState } from 'react'
import { useEffect, useState } from 'react'

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

useEffect(() => {
setHasComponent(component.has(entity))
}, [entity, component])

return hasComponent
}

0 comments on commit c62a668

Please sign in to comment.