Answer the question
In order to leave comments, you need to log in
Proper inheritance/reuse in styled-components?
What is the best way to link styled-components for reuse?
There are different forms on the project, which can change different parameters, but at the same time there is the same moment - indents. There is a title, then there are form fields, then the submit button.
I tried to make a base component like this:
const AppForm = styled.form``
AppForm.Title = styled.h1`
margin-bottom: 20px;
`
AppForm.Field = styled(TextField)`
margin-bottom: 10px;
`
AppForm.Button = styled(Button)`
margin-top: 20px;
`
const LoginForm = styled(AppForm)`
width: 500px;
`
LoginForm.Image = styled(AppForm.Field)`
margin: 50px 0;
`
LoginForm.Image.defaultProps = {
as: 'img'
}
<LoginForm>
<AppForm.Field/>
<AppForm.Field/>
<LoginForm.Image/>
<AppForm.Button>Submit</AppForm.Button>
</LoginForm>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question