Styles from stylesheet is not applied.

huangapple go评论93阅读模式
英文:

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:

  1. {hasCopiedInvitationLink && (
  2. <LinkCopiedToolTip
  3. disclaimerText={disclaimerText}
  4. isDesktop={isDesktop}
  5. tooltipStyle={{ ...tooltipContainer, ...fadeOut }}
  6. setHasCopiedInvitationLink={setHasCopiedInvitationLink}
  7. />
  8. )}

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.

  1. export const LinkCopiedToolTip = ({
  2. disclaimerText,
  3. isDesktop,
  4. tooltipStyle,
  5. setHasCopiedInvitationLink,
  6. }) =&gt; {
  7. const [fadeOutTooltip, setFadeOutTooltip] = useState&lt;boolean&gt;(false)
  8. ...
  9. ...
  10. ...
  11. return (
  12. &lt;View style={{ ...tooltipStyle.tooltipContainer, ...(fadeOutTooltip &amp;&amp; tooltipStyle.fadeOut) }}&gt;
  13. &lt;Tooltip hasFluidWidth arrow={isDesktop ? &#39;left&#39; : &#39;top&#39;}&gt;
  14. {disclaimerText}
  15. &lt;/Tooltip&gt;
  16. &lt;/View&gt;
  17. )
  18. }

The component LinkCopiedToolTip gets rendered depending on the state hasCopiedInvitationLink like this in a parent component:

  1. {hasCopiedInvitationLink &amp;&amp; (
  2. &lt;LinkCopiedToolTip
  3. disclaimerText={disclaimerText}
  4. isDesktop={isDesktop}
  5. tooltipStyle={{ ...tooltipContainer, ...fadeOut }}
  6. setHasCopiedInvitationLink={setHasCopiedInvitationLink}
  7. /&gt;
  8. )}

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:

&lt;View style={{ ...tooltipStyle.tooltipContainer, ...(fadeOutTooltip &amp;&amp; tooltipStyle.fadeOut) }}&gt;

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 }}

huangapple
  • 本文由 发表于 2023年2月14日 00:01:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438326.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定