question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning: Received `true` for non-boolean attribute `gray`.

See original GitHub issue

How 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:closed
  • Created 6 years ago
  • Reactions:132
  • Comments:30 (4 by maintainers)

github_iconTop GitHub Comments

409reactions
MisterTakicommented, Oct 14, 2017

Temporarily: <Button gray={gray ? 1 : 0} to='path/to/page'>hoge</Button>

It works for me 😃

194reactions
probablyupcommented, Sep 20, 2018

There’s nothing to be done here. Just don’t pass the prop to the DOM element if you’re using a custom component.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found