Styled-Componentsを使ってコンポーネントを作成しています。
下記のようなJSXで<Button remove/>
が一つしかない場合にprops.remove
や:only-child
を使ってdisplay: none;
にする方法はあるのでしょうか?
<Button add/>
をクリックすると新たにitemが追加され、<Button remove/>
が表示されるといった形を考えています。
<Container> {items.map(item => <Item key={item.id}> <ItemContainer> <Text>{item.text}</Text> <ButtonsGroupe> <Button remove onClick={Remove}>Remove</Button> // :only-child: {display: none;} <Button add onClick={Add}>Add</Button> </ButtonsGroupe> </ItemContainer> </Item> )} </Container>
解決策(Meganezaru様ありがとうございます)
export const Button = styled.div` ${ItemContainer}:only-child & { ${props => props.remove && ` display: none; `} } `;
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/29 05:35
2018/12/29 06:49
2018/12/29 06:51
2019/01/01 02:38
2019/01/01 11:31