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.

React warning using styled function

See original GitHub issue
  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

Using the following code snippet

export const styledBy = (property, mapping) => props =>
  mapping[props[property]];

const AppBarContent = styled('div')({
  flexGrow: 1,
  display: 'flex',
  justifyContent: styledBy('alignContent', {
    start: 'flex-start',
    end: 'flex-end',
    center: 'center',
  }),
});


// ....

<AppBarContent alignContent={props.alignContent}>
  {props.children}
</AppBarContent>

Current Behavior 😯

index.js:1437 Warning: React does not recognize the alignContent prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase aligncontent instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Steps to Reproduce 🕹

Link: https://github.com/straw-hat-team/react-admin

  1. yarn start
  2. Notice the console error

Context 🔦

Your Environment 🌎

Tech Version
Material-UI 4.0.0-beta.1
React 16.8.6
Browser
TypeScript 3.4.5
etc.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
ggascoignecommented, Jun 13, 2019

I think that I’m missing something; is there any way to stop forwarding props to an html element (such as div), while still using styled(). I can see how to do it with makeStyles/useStyles since you get explicit control of what gets passed to your div, but not when using styled.

It is as simple as, don’t pass props to styled html elements?

4reactions
Puspendertcommented, Nov 22, 2021

import styled from "styled-components" doesn’t have this problem, but import {styled} from "@mui/material" still giving this warning. Any official solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React warning using styled function #15614 - mui/material-ui
I had a new look at the issue. emotion and styled-components report a warning, shouldForwardProp is supported by both. You can use the...
Read more >
Getting warning from props passed in MUI styled components ...
Warning : React does not recognize the isLarge prop on a DOM element. If you intentionally want it to appear in the DOM...
Read more >
You may see this warning because you've called styled inside ...
The component styled.div with the id of “sc-fzplWN” has been created dynamically. You may see this warning because you've called styled ...
Read more >
FAQs - styled-components
The warning message below indicates that non-standard attributes are being attached to HTML DOM elements such as <div> or <a>. If you are...
Read more >
How to use styled components with Material UI in a React app
The styled() method from styled-components takes as input a React component and outputs another React component with a different style. It is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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