英文:
Styles from stylesheet is not applied
问题
I'm trying to style a component but it doesn't look like the styles that I'm using is getting applied.
toolTipStyle gets prop-drilled down to the component, but I can see that they exist if I console.log them.
The component LinkCopiedToolTip gets rendered depending on the state hasCopiedInvitationLink like this in a parent component:
{hasCopiedInvitationLink && (
  <LinkCopiedToolTip
    disclaimerText={disclaimerText}
    isDesktop={isDesktop}
    tooltipStyle={{ ...tooltipContainer, ...fadeOut }}
    setHasCopiedInvitationLink={setHasCopiedInvitationLink}
  />
)}
Any takes? I'm at my wits' end here. Thanks!
Tried a bunch of stuff. If I just hardcode the styles directly it works.
英文:
I'm trying to style a component but it doesn't look like the styles that I'm using is getting applied.
toolTipStyle gets prop-drilled down to the component but and I can see that they exist if I console.log them.
export const LinkCopiedToolTip = ({
  disclaimerText,
  isDesktop,
  tooltipStyle,
  setHasCopiedInvitationLink,
}) => {
  const [fadeOutTooltip, setFadeOutTooltip] = useState<boolean>(false)
...
...
...
  return (
    <View style={{ ...tooltipStyle.tooltipContainer, ...(fadeOutTooltip && tooltipStyle.fadeOut) }}>
      <Tooltip hasFluidWidth arrow={isDesktop ? 'left' : 'top'}>
        {disclaimerText}
      </Tooltip>
    </View>
  )
}
The component LinkCopiedToolTip gets rendered depending on the state hasCopiedInvitationLink like this in a parent component:
{hasCopiedInvitationLink && (
          <LinkCopiedToolTip
            disclaimerText={disclaimerText}
            isDesktop={isDesktop}
            tooltipStyle={{ ...tooltipContainer, ...fadeOut }}
            setHasCopiedInvitationLink={setHasCopiedInvitationLink}
          />
        )}
Any takes :)? I'm at my wits end here. Thanks!
Tried a bunch of stuff. If I just hardcode the styles directly it works.
答案1
得分: 1
以下是翻译好的部分:
"看起来你试图访问 tooltipStyle 上不存在的属性:"
<View style={{ ...tooltipStyle.tooltipContainer, ...(fadeOutTooltip && tooltipStyle.fadeOut) }}>
要让它工作,你需要更新传递给 LinkCopiedToolTip 的样式的语法,并移除展开 (...) 运算符:
tooltipStyle={{ tooltipContainer, fadeOut }}
英文:
It looks like you are trying to access properties that do not exist on tooltipStyle:
<View style={{ ...tooltipStyle.tooltipContainer, ...(fadeOutTooltip && tooltipStyle.fadeOut) }}>
To get this to work you need to update the syntax where the styles are fed to LinkCopiedToolTip and remove the spread (...) operator:
tooltipStyle={{ tooltipContainer, fadeOut }}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论