stylization of other files

Asked

Viewed 16 times

-1

Good night! I’m new here in the stack and have little experience with React and Styled-Components. I have an excerpt of stylization below that I want to reuse in another part of my code without having to keep typing the same stylization commands, how to do this? I saw a post on how to assemble, but I’m not able to use it in another part of the code.

this code snippet is in a style.jsx file in the helpers folder.

import { css } from 'styled-components';

const mixins = {
  flexCenter: css`
    display: flex;
    align-items: center;
    justify-content: center;
  `,
};

export default mixins;

I want to reuse the above code in a part of the code below.

import React from 'react';
import styled from 'styled-components';
import { mixins } from '../helpers/style';

const Container = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 0 150px;
  /* ... */
`;

I will perform the same thing for other parts of the code with other stylings.

  • You are exporting the mixins variable as default, so when importing you should not use the keys, that is, use 'import mixins from' .. /helpers/style'. At the heart of your question, try inserting mixin as an interpolation${mixins.flexCenter}'.

  • worked well @Vandersantos worked perfectly. Thank you so much for the support!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.