Styled-components organization [closed]

This is what most of my big production applications built with styled-components look like: src ├── App │ ├── Header │ │ ├── Logo.js │ │ ├── Title.js │ │ ├── Subtitle.js │ │ └── index.js │ └── Footer │ ├── List.js │ ├── ListItem.js │ ├── Wrapper.js │ └── index.js ├── shared │ ├── … Read more

You should not use Route or withRouter() outside a Router when using react-router 4 and styled-component in react

Make sure you wrap the main react render code in the Router. For example, with react-dom you need to wrap the app in Browser-Router. If this is a Udacity project, this is typically the index.js file. import { BrowserRouter } from ‘react-router-dom’; ReactDOM.render( <BrowserRouter> <App /> </BrowserRouter> , document.getElementById(‘root’));

Styled-components and react-bootstrap?

You can extend the style keeping the original styles of the component from bootstrap. You will find more documentation on using third party libraries like react bootstrap with styled-components here. const StyledButton = styled(Button)` color: palevioletred; font-size: 1em; margin: 1em; padding: 0.25em 1em; border: 2px solid palevioletred; border-radius: 3px; `; Here is a sandbox for … Read more

Using styled components with Typescript, prop does not exist?

The styled component will have to specify the prop to pass to the component like styled(“h2”)<IProps>. You can read more about the pattern from documentation css is not required here, it is added as a helper when you need to actually return CSS from a function. Check out conditional rendering. Taking these into account, the … Read more

Warning: Prop `className` did not match. when using styled components with semantic-ui-react

This warning was fixed for me by adding an .babelrc file in the project main folder, with the following content: { “presets”: [“next/babel”], “plugins”: [[“styled-components”, { “ssr”: true }]] } See following link for an example: https://github.com/nblthree/nextjs-with-material-ui-and-styled-components/blob/master/.babelrc

styled-components – how to set styles on html or body tag?

You can, of course, maintain a separate CSS file that you include in your HTML via a <link> tag. For v4: Use createGlobalStyle from Styled-components. import { createGlobalStyle } from ‘styled-components’ const GlobalStyle = createGlobalStyle` body { color: ${props => (props.whiteColor ? ‘white’ : ‘black’)}; } ` <React.Fragment> <GlobalStyle whiteColor /> <Navigation /> {/* example … Read more

idiomatic way to share styles in styled-components?

You can either share actual CSS strings or share styled-components components: Share CSS strings: import {css} from ‘styled-components’ const sharedStyle = css` color: green ` // then later const ComponentOne = styled.div` ${sharedStyle} /* some non-shared styles */ ` const ComponentTwo = styled.div` ${sharedStyle} /* some non-shared styles */ ` Share actual styled-components: const Shared … Read more

Before and After pseudo classes used with styled-components

Pseudo-selectors in styled-components work just like they do in CSS. (or rather, Sass) Whatever isn’t working is likely a problem in your specific code, but that’s hard to debug without seeing the actual code! Here is an example of how to use a simple :after: const UnicornAfter = styled.div` &:after { content: ” 🦄”; } … Read more