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.

How to merge `css` styles with `cloneElement`?

See original GitHub issue

Given an element with css styles, I’d like to clone it and add more css styles.

Using a custom cloneElement throws an error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.

…and using React.cloneElement doesn’t merge the styles.

Any ideas?

cc @Andarist

Codesandbox

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Andaristcommented, Jan 11, 2020

Yes, arrays will be always supported and its a good composition mechanism 😃

0reactions
moroshkocommented, Jan 24, 2020

Yep, thanks @Andarist for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - How can I add styles to all the children of an element
Then return a clone of each child with an appropriate style like so using React.cloneElement . This will shallowly merge any property ...
Read more >
Using the React.cloneElement() function to clone elements
In this in-depth tutorial, learn how to clone and manipulate elements three different ways using the React.cloneElement function.
Read more >
How to use React.cloneElement() function? - GeeksforGeeks
The first argument is the element that we want to clone. The second argument will be additional props that we want to add...
Read more >
Example of React.cloneElement - CodePen
About CSS Base. It's a common practice to apply CSS to a page that styles elements such that they are consistent across all...
Read more >
The css Prop - Emotion
babelrc your styles will not be applied. The plugin is not compatible with the css prop. When using React.cloneElement you can't easily add...
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