This repository was archived by the owner on Apr 25, 2026. It is now read-only.
Repository navigation
Best way to add extra styles to a React component #899
Answered
by
funwithtriangles
funwithtriangles
asked this question in
Help
// Here I have some sort of component without any margins
const SomeButton = function () {
return <button>Bar</button>;
};
// I want to use the above component but just add some margins, but this doesn't work
const ButtonWithMargin = styled(SomeButton, {
marginLeft: "1rem"
});
export default function App() {
return (
<div>
<span>Foo</span>
<ButtonWithMargin />
</div>
);
}What's the best way to extend a component styles? I assumed I could use Perhaps there is some pattern I'm missing? I'm aware this could be achieved by doing something like: const SomeButton = styled("button", {...})But for the sake of argument, let's say my button is complex and needs to be a React component. https://codesandbox.io/s/stitches-responsive-problem-forked-uimoq |
Answered by
funwithtriangles
Dec 15, 2021
Replies: 1 comment
|
Nevermind, I found the solution, just need to use the import { styled } from "./stitches.config";
import "./styles.css";
const SomeButton = function ({ className }) {
return <button className={className}>Bar</button>;
};
const ButtonWithMargin = styled(SomeButton, {
marginLeft: "1rem"
});
export default function App() {
return (
<div>
<span>Foo</span>
<ButtonWithMargin />
</div>
);
} |
0 replies
Answer selected by
funwithtriangles
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nevermind, I found the solution, just need to use the
classNameprop!