*一部を抜粋 constructor(props) { super(props); this.state = { cssstyle: false, }; } cssChange= () => { this.setState({ cssstyle: !this.state.cssstyle}); }; render() { const cssstyle= ClassNames({ [theme.cssstyle]: this.state.cssstyle, }); return ( <section> <div className={cssstyle} onClick={ this.cssChange.bind(this) } >ボタン1</div> <div className={cssstyle} onClick={ this.cssChange.bind(this) } >ボタン2</div> <div className={cssstyle} onClick={ this.cssChange.bind(this) } >ボタン3</div> </section> ); };
cssファイル
section > div { width:100px; height:20px; color:#333; } .cssstyle { border:1px solid #ff0000; background:#000; color:#fff; }
このような形でボタンが3つあり、
くりっくしたものだけ、.cssstyleのクラスを付与したいのですが、
上記ですと当然どのボタンを押しても全部のボタンに.cssstyleがついてしまいます。
jqueryとかであれば簡単なのですがreactの場合、どのように
クリックしたもの以外はスタイルを外すもしくは最初からくりっくしたものだけしか
クラスがつかないようにするのでしょうか?
javascriptのremove()とかでレンダーされた後に無理やりcssを消す方法は
できたのですができれば、react内できれいに行いたいと思いまして・・
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/27 06:50
2019/09/27 06:54
2019/09/27 07:00
2019/09/27 07:27
2019/09/27 07:28