javascript - Get color of target html element in React -


trying color of html element using react, pass to redux action/reducer.

jsx

<div>    <button stylename="css_toggle" id ="css" onclick {this.handleclick}>css</button> </div> 

event handler

handleclick(e){   const{dispatch} = this.props;   console.log(`e.target: ${e.target.style}`);   dispatch(currview(e.target.id, e.target.style.background)); } 

console/redux console returns empty values styles.

i using react-css-modules/css-modules, , anomaly can think of.

any ideas more welcome, thank you.

edit: have created branch stackoverflow question: https://github.com/charliegreenman/pixellight/tree/stackoverflow-37583025

note: data flow of app, there single static value, populates rest of app dynamic. in response, suggestion(s), after thought, have decided proper way architect app.

you can use refs reliable reference element.

jsx

<div>     <button id ="css"         stylename="css_toggle"         onclick={this.handleclick}         ref={(e) => { this.csstogglebutton = e; }}>         css     </button> </div> 

event handler

handleclick() {     const id = this.csstogglebutton.id;     const background = this.csstogglebutton.style.background;     this.props.dispatch(id, background); } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo