React warns about a custom boolean prop on a styled-components element
Warning: Received `false` for a non-boolean attributeShort 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.
Fix it fast
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/ | head2Match what you see, then jump to its fix
- 1
The 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
The 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
A 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
- 1
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.jsx2Fix
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 devConfirmed by styled-components.com
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/ | head2Fix
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 devConfirmed by styled-components.com
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 | head2Fix
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 devConfirmed by react.dev
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fixWeb apps
An axios call never finishes when the API server stops answering
code: 'ECONNABORTED'
Axios has no timeout unless you give it one: the default is 0, which means wait forever.
3 causes, each with a fix