Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

React warns about a custom boolean prop on a styled-components element

ErrorWarning: Received `false` for a non-boolean attribute

Short answer

styled-components passes props it does not know straight to the DOM element, and React warns when a custom prop such as active or isOpen lands there. Rename style-only props with a leading dollar sign (transient props), or filter them with shouldForwardProp. Also check any spread of props onto a plain tag.

  • Applies to React 19, styled-components 6, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the attribute name in the warning. Then find the styled component that receives it and check whether the prop is only used for styling.

    grep -rn "isActive\|\$isActive" src/ | head
  2. 2Match what you see, then jump to its fix

    1. 1The warning names a custom prop like active, isOpen or primary, used inside the template literal.A style-only prop is forwarded to a DOM elementFix
    2. 2The prop comes from a shared component or has to keep its name, for example a prop also used by a wrapped component.A prop you cannot rename is still forwardedFix
    3. 3A wrapper component writes {...props} on a div or button, and the warning names a prop meant for the wrapper.Props are spread onto a plain DOM tagFix

What does the error look like?

  • Warning: Received `false` for a non-boolean attribute

Cause 1 of 3

A style-only prop is forwarded to a DOM element

1Check

A prop that is only read in the CSS interpolation has no reason to reach the DOM.

grep -n "props =>" src/components/Tab.jsx

2Fix

Prefix the prop with a dollar sign. It becomes a transient prop that styled-components does not render to the DOM.

const Tab = styled.div`
  color: ${(props) => (props.$active ? 'tomato' : 'black')};
`;

<Tab $active={isActive}>Home</Tab>

3Verify

Reload the page and watch the console. The warning should be gone and the colour should still change.

npm run dev

Confirmed by styled-components.com

Did this fix it?

Cause 2 of 3

A prop you cannot rename is still forwarded

1Check

Decide which props must not reach the element.

grep -rn "styled(" src/ | head

2Fix

Filter props with shouldForwardProp through withConfig. A prop that fails the test is not passed down, like a transient prop.

const Box = styled('div').withConfig({
  shouldForwardProp: (prop) => !['active'].includes(prop),
})`
  opacity: ${(props) => (props.active ? 1 : 0.5)};
`;

3Verify

Render the component with active true and false. The warning should not appear for either.

npm run dev

Confirmed by styled-components.com

Did this fix it?

Cause 3 of 3

Props are spread onto a plain DOM tag

1Check

React lists spreading props with {...props} or cloneElement(element, props) as a cause of the unknown-prop warning.

grep -rn "{...props}\|{...rest}" src/components | head

2Fix

Pull out the props meant for the wrapper and spread only the rest.

function MyDiv(props) {
  const { layout, ...rest } = props;
  return <div {...rest} style={getStyle(layout)} />;
}

3Verify

Render the wrapper with the extra prop. The console should be clean.

npm run dev

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Name every style-only prop with a leading dollar sign from the start.
  • In wrappers, destructure the props you consume and spread only the remainder.
  • Treat console warnings as test failures in CI for components that wrap DOM elements.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.