Warning: Received `true` for non-boolean attribute `gray`.
See original GitHub issueHow can I resolve this warning?
Warning: Received `true` for non-boolean attribute `gray`. If this is expected, cast the value to a string. warning.js:33
The code is looks like this.
export const Button = styled(Link).attrs({
width: props => props.width || '100%',
})`
display: block;
width: ${props => props.width};
text-align: center;
color: #fff;
background-color: ${props => props.gray ? '#bababa' : '#ea352d'};
`;
export default class Hoge extends React.PureComponent {
render() {
return (
<Button gray to='path/to/page'>hoge</Button>
);
}
}
When I passed gray
props, the warning happened.
modules version.
- styled-components: 2.2.0
- react-router: 4.2.0
- react-router-dom: 4.2.2
Issue Analytics
- State:
- Created 6 years ago
- Reactions:132
- Comments:30 (4 by maintainers)
Top Results From Across the Web
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 >How to fix the 'Received "true" for a non-boolean attribute' error
The trick is to use the unary plus operator to convert boolean to number. before your booleans values. According to MDN unary operator...
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 >Warning: Received 'True' For A Non-Boolean Attribute 'Exact'
The solution on githubWarning: Received 'true' for nonboolean attribute 'gray'. solution. React's recognition of boolean attributes can be solved by the ...
Read more >接收到非布尔属性Warning: Received `false` for a non-boolean ...
github上的解决方案-Warning: Received 'true' for non-boolean attribute 'gray'. 解决方案. React对boolean类型的attribute的识别方式问题,可以采用 ...
Read more >
Top Related Medium Post
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
Temporarily:
<Button gray={gray ? 1 : 0} to='path/to/page'>hoge</Button>
It works for me 😃
There’s nothing to be done here. Just don’t pass the prop to the DOM element if you’re using a custom component.