Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config issues #1041

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading