K
K
Kafkae2019-03-28 21:20:32
React
Kafkae, 2019-03-28 21:20:32

How to send props to emotion (similar to styled components)?

How to throw props in emotion (similar to styled components). And to have a default value if there are no props.
Code link - https://codesandbox.io/s/ly8vp183p9

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-03-28
@Kafkae

Just like any other component. And you can see examples of using props in the documentation .
UPD. I looked at the code - so you have already done part of the work. Some of the components already accept props - Container, for example, or Wrapper. Let's take Wrapper - it has itemWidth and itemHeight. Well, great: Say, do you need a default value? Well, let it be instead , for example. Or you can rewrite the component like this:

export const Wrapper = styled.article(({
  itemWidth,
  itemHeight = '200px',
}) => ({
  backgroundColor: '#efefef',
  margin: '5px',
  height: itemHeight,
  width: itemWidth,
}));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question