警告:收到非布尔属性的“false".如何为自定义布尔属性传递布尔值? [英] Warning: Received `false` for a non-boolean attribute. How do I pass a boolean for a custom boolean attribute?

查看:111
本文介绍了警告:收到非布尔属性的“false".如何为自定义布尔属性传递布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

警告:收到非布尔属性 `comingsoon` 的 `false`.如果要将其写入 DOM,请改为传递一个字符串:comingsoon="false" 或comingsoon={value.toString()}.

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

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

解决方案

试试这个:

comingsoon={value ?1:0}

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()}.

How do I pass a boolean in a custom attribute for React?

I'm using styled-components and passing the attribute through the component. Here is a picture of how I'm passing the attr.

passing boolean custom attr as "comingsoon"

styled-components css props

解决方案

Try this instead:

comingsoon={value ? 1 : 0}

这篇关于警告:收到非布尔属性的“false".如何为自定义布尔属性传递布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆