New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The component styled.div with the id of "sc-fzqAui" has been created dynamically. You may see this warning because you've called styled inside another component. To resolve this only create new StyledComponents outside of any render method and function component. #3117
Comments
Hi, |
I'm getting the same. So, what is the right way to do it? Where should I declare styled components? |
Hi,
I think you're doing it like that:
That's why you've got the warning. |
@CyrilQuandalle Thank you very much for pointing out the problem, my code Is there a good way to get around this because I want to get the parent context parameter in the component Once again thank you |
You can do that like that :
|
wow, So simple, why didn't I think, thank you for your kind help, I will try to get rid of this mistake |
@CyrilQuandalle Thank you so much that I have solved the problem completely using your method. Now all the mistakes are gone. It's great |
@CyrilQuandalle Even I am facing the same issue. I like to keep my style objects in a separate JS file. But in the other case, I write something like the below: and use it like below: In this case, I face the issue under discussion. What would be the workaround? |
Hi @praveendass , I never used it like that ;-). Maybe move |
@CyrilQuandalle Hey thanks for the quick response! const getColumn = (ratio) => {
} Any suggestion on how I can get around this? |
I dont know then. Why do you need a function to render your divs as you can just pass a props for the ratio to it ?
|
@CyrilQuandalle Just figured it out... :D |
Sorry for adding another comment here — I’m not understanding what to do. Receiving the same warning, yet nothing I do can fix this. Like @eugle, I, too, want to keep my styled-components in separate JS files, since many SCs are used as building blocks over and over again. How can I refactor the following? Section.jsexport default styled.div`
position: relative;
width: 100%;
` Homepage.jsimport Section from '@/Section'
const Homepage = () => (
<Section>
Hello, world!
</Section>
)
export default Homepage Tried various changes to no avail. |
Hi @heymartinadams , What warning do you have ? |
Here’s the error message, @CyrilQuandalle:
(for each and every SC) Mmh... my situation is probably made more complex in that I’m using Preact (instead of React) as well as the NextJS framework. Could that perhaps be the cause of it? |
Yes it could be caused by Preact or NextJS. I just found that I dont know if it fits your case : https://github.com/styled-components/styled-components/issues/3174 |
Thank you, @CyrilQuandalle! Subscribed to the corresponding Preact issue. At least it seems it’s only a warning trigger that’s at issue, not an actual problem with the code or execution. |
This is work. Thank you @CyrilQuandalle |
Hi, Im getting the same warning message when I tried to use component from react styled loaders is there any solution? |
fix: remove react warning (missing keys) fix: remove styled-component dynamically created (see styled-components/styled-components#3117) chore: bump multiple dependencies refactor: run prettier
fix: remove react warning (missing keys) fix: remove styled-component dynamically created (see styled-components/styled-components#3117) chore: bump multiple dependencies refactor: run prettier
@CyrilQuandalle Hello, i have the same issue while using react-data-table-component ,i posted my problem here jbetancur/react-data-table-component#840 , the problem is i didn't use styledComponent at all |
I also got a similar problem with my svgs
I'm creating the Icon component based on the svg name. And I can't figure out how not to do this without triggering the dynamically created error. Can't someone shed some light in this? |
You can try with
|
Hi ,I have written the code like this but I am getting an error |
Came across the same warning and it did not appear that the styled component was actually being created dynamically, at least not to my un(styled)trained eyes. Here's a repro sandbox on version 5.3.5 of styled-components in case this helps. The warning was not thrown on version 5.0.0-beta which is currently the default version used in the base codesandbox provided when creating a new issue. The issue comes from requiring a styled component within the body of the functional component, like so: const Consumer = ({ componentName }) => {
const Component = require(`./components`)[componentName];
return <Component />;
}; A workaround is to import all components outside of the functional component: import * as Components from "./components"
const Consumer = ({ componentName }) => {
const Component = Components[componentName]
return <Component />;
}; Hope this helps someone. |
I solved it through this nextjs documentation in the link below nextJs: https://nextjs.org/docs/advanced-features/custom-document |
The component styled.div with the id of "sc-fzqAui" has been created dynamically.
You may see this warning because you've called styled inside another component.
To resolve this only create new StyledComponents outside of any render method and function component.
Is there any way to get rid of this warning? There will be a warning in the development environment, and everything is normal in the production environment
This is my actual component code
Based on the component's properties, I wrapped an NPM package,
@eugle/oneui
The text was updated successfully, but these errors were encountered: