score:3
Accepted answer
I don't see a reason for three components, a pattern that works for me is using dot notation:
const StyledButton = styled.button``;
const Button = (props) => {
return (
<StyledButton className={props.className}>
{props.loading && <LoadingSpinner />}
{props.children}
</StyledButton>
);
};
Button.Styled = StyledButton;
export default Button;
In this way, you have a pattern where Component.Styled
(if available) will always hold the runtime CSS-in-JS object which you can target.
Then in ButtonGroup
implementation:
import { Button } from "@components";
// You can target the className
const ButtonGroup = styled.div`
${Button.Styled} { ... }
`;
// You can apply styles
styled(Button)
// You can use the component
<Button />
// Or extend style etc
<OtherButton as={Button.Styled} .../>
Source: stackoverflow.com
Related Query
- How to style a nested functional component using styled components
- How to style a functional stateless component in Reactjs using classes object
- How to change the inputted text's style inside an input element using Styled Components - React
- How to style an SVG using React styled components by passing the SVG as prop?
- How to give style a child component of normal component at Styled Components lib
- Styled Components - How to style a component passed as a prop?
- Styled components - How do I create a style that inherits a component and is able to send props to the parent?
- How to Declare Styled Components Using React Component Class Syntax
- How to style react styled components using classNames
- How to style components using makeStyles and still have lifecycle methods in Material UI?
- How do I get an attribute of an element nested in a React component using Jest and/or Enzyme?
- How to unit test a style of a React Component using Jest.js?
- How to test styled Material-UI components wrapped in withStyles using react-testing-library?
- How to pass props to a styled component in emotion? Using TypeScript
- Apply styled component style to a third party components
- How to test methods inside functional component using enzyme as instance() returns null for shallow wrapper?
- How to pass custom attribute to a styled component in a functional component?
- How to convert functional component using hooks to class component
- How to debounce a callback in functional component using hooks
- How to properly extend a styled component using TypeScript
- How to serve a React component library dependent on Styled Components to another library that also has a Styled Comopnents dependency?
- how to use AppState in a functional component and hooks? Necessary or am I using useEffect incorrectly?
- How to override style of nested Material UI component from the ancestors?
- Using React how do I toggle the visibility of a nested component from a container component?
- how to change image src using props with styled component and react
- How to use Render Props in functional component using typescript
- Dependency cycle issue when using Styled Components alongside compound component pattern
- How to solve closures issue when using React functional component with React.memo?
- How to test styled components using Enzymes shallow and styled-component's ThemeProvider?
- How to add action to functional component using Redux and ReactJS
More Query from same tag
- Changing two states sequentially throws an error
- How to unit test apollo links
- redux-form unable to type values in fields
- React Hover Styling
- How to update entire Array state in React?
- React - Typescript interfaces - errors when get props from union types
- Dynamic render react child component
- Newbie react question: Target container is not a DOM element when calling react from html
- Async await and setTimeout are not working in ReactJS
- Include only used imports in the packaged bundle ReactJS
- React Router dynamic url rendering over static url
- How to pass a value to this react component
- React Typescript: Line 0: Parsing error: Cannot read property 'name' of undefined
- How to map JSON data in React?
- How to test alias import
- Send Data from Child Component To Parent Component
- ReactJS/Material-Table: How can I autofill a row if someone selects a certain "lookup"/dropdown option?
- React onTouchStart not firing
- How can I get a modal to be larger on desktop?
- GoogleMaps React: Open InfoWindow by Default - not from onClick
- Build React component from string with placeholders
- React. How to pass props inside a component defined on a prop?
- Trying to call a handler on a custom element not working
- React - Correct path to display image
- Scrollable responsive content between components
- Ternary operator doesn't work as expected
- React-Select & React-Flow overlapping
- Function returning promise, instead of value
- Why got "This expression is not callable..." errors from typescript and react js?
- Why React function do not retuning div?