gpt4 book ai didi

reactjs - 警告 : Received `false` for a non-boolean attribute. 如何为自定义 bool 属性传递 bool 值?

转载 作者:行者123 更新时间:2023-12-03 13:06:18 26 4
gpt4 key购买 nike

Warning: Received `false` for a non-boolean attribute `comingsoon`.

If you want to write it to the DOM, pass a string instead:
comingsoon="false" or comingsoon={value.toString()}.

如何在 React 的自定义属性中传递 bool 值?

我正在使用样式组件并通过组件传递属性。这是我如何传递 attr 的图片。

passing boolean custom attr as "comingsoon"

styled-components css props

最佳答案

5.1 开始,您现在可以使用 transient props ($) 阻止将 props 传递给 DOM 元素。

const Comp = styled.div`
color: ${props =>
props.$draggable || 'black'};
`;

render(
<Comp $draggable="red" draggable="true">
Drag me!
</Comp>
);

关于reactjs - 警告 : Received `false` for a non-boolean attribute. 如何为自定义 bool 属性传递 bool 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49784294/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com