Received `true` for a non-boolean attribute `block`
See original GitHub issueIt seems like props are passed as an attribute and when I pass boolean, It throws error on the console. I am using next.js with typescript.
This is the error
Warning: Received `true` for a non-boolean attribute `block`.
If you want to write it to the DOM, pass a string instead: block="true" or block={value.toString()}.
button
functionTemplate/</<@webpack-internal:///./node_modules/tailwind-styled-components/dist/tailwind.js:34:101
Component looks like this
import tw from 'tailwind-styled-components';
interface Props {
layout?: 'primary' | 'outline';
disabled?: boolean;
block?: boolean;
size?: 'small' | 'medium' | 'large';
}
const Button = tw.button`
flex justify-center items-center border border-solid font-medium rounded-sm transition-all duration-300 ease-in-out
${(props: Props) =>
props.layout === 'primary' &&
'border-primary-400 bg-primary-400 text-white hover:bg-primary-500 hover:border-primary-600'}
${(props: Props) =>
props.layout === 'outline' &&
'border-gray-300 text-gray-700 hover:border-blue-500 hover:text-blue-500'}
${(props: Props) =>
props.disabled && 'bg-gray-50 border-gray-200 text-gray-200'}
${(props: Props) => props.size === 'small' && 'px-2 py-2 text-xs'}
${(props: Props) => props.size === 'medium' && 'px-4 py-3 text-xs'}
${(props: Props) => props.size === 'large' && 'px-5 py-4 text-lg'}
${(props: Props) => props.block && 'w-full'}
`;
export default Button;
The workaround is using number as boolean block ? 1 : 0
Issue Analytics
- State:
- Created 2 years ago
- Comments:18 (16 by maintainers)
Top Results From Across the Web
How to fix the 'Received "true" for a non-boolean attribute' error
I'll present an alternative to this solution. The trick is to use the unary plus operator to convert boolean to number.
Read more >Warning: Received `false` for a non-boolean attribute. How do ...
This error with styled-components appears to be due to styled() attempting to apply a boolean ...
Read more >Warning: Received true for non-boolean attribute gray . #1198
How can I resolve this warning? Warning: Received `true` for non-boolean attribute `gray`. If this is expected, cast the value to a string....
Read more >How to Fix ' Received false for non-boolean attribute' Errors
The "Warning: Received false for a non-boolean attribute className." warning happens in React when you try to conditionally set a attribute, ...
Read more >Styled-components "Warning Received `true` for non-boolean ...
Ok, first of all, what does this error mean. It means that you passed boolean value for the property of a DOM element....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
New NPM package released with transient props support and way better typing. Many thanks to @m50 and @cemreinanc for your help!
Yeah I read the same stack overflow.
Perfect then we will implement it once typescript 4.4 is out.
I’ll just document it for now.
Thank you so much for your help 🙏