質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

解決済

1回答

515閲覧

StyledComponentの継承でタグ変更

MapleMomij

総合スコア11

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2018/03/19 09:23

前提・実現したいこと

ReactのstyledComponentを用いてSPAの開発をしています。
あらかじめ定義していたstyledComponentを継承してボタンを作っているのですが、そのスタイル継承しつつタグを設定することはできないのでしょうか?
例えば、buttonタグで作ったもののスタイルを継承しつつ、それをaタグとして使えないでしょうか?

ソースコード

jsx

1 2export const Button = styled.button` 3 font-size: 13px; 4 border-radius: 20px; 5 height: 30px; 6 padding:0; 7 cursor: pointer; 8 transition: all .2s ease; 9 font-weight: bold; 10 min-width: ${props => props.width ? props.width : '100px'}; 11 &:hover { 12 opacity:0.7; 13 } 14`; 15------------------ 16 17const TwitterBtn = Button.extend`←ここでaタグを指定したい 18 border-radius: 100px; 19 width: 220px; 20 height: 41px; 21 margin: 0 auto; 22`; 23 24render(){ 25 return ( 26 <TwitterBtn> 27 Twitterで新規登録 28 </TwitterBtn> 29 ) 30} 31 32

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

export const Button = styled.button` font-size: 13px; border-radius: 20px; height: 30px; padding:0; cursor: pointer; transition: all .2s ease; font-weight: bold; min-width: ${props => props.width ? props.width : '100px'}; &:hover { opacity:0.7; } `; const AnchorButton = Button.withComponent('a') // +追加 const TwitterBtn = AnchorButton.extend` // +継承元変更 border-radius: 100px; width: 220px; height: 41px; margin: 0 auto; `;

const AnchorButton = Button.withComponent('a')

これで行けると思います。

投稿2018/03/19 09:34

編集2018/03/19 09:35
HayatoKamono

総合スコア2415

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

MapleMomij

2018/03/19 09:46

大変助かりました!ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問