Quantcast
Channel: Cannot set property 'color' of undefined getting this error in React - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Cannot set property 'color' of undefined getting this error in React

$
0
0

I am trying to change colour of text in h1 tag when I click button. I am calling change colour function but when onclick it executes at that time it is showing error in the inside statement [ this.styling_text.color="black" ]

import React,{Component} from 'react';class InlineDynamic extends Component{     changeColor = () =>{           this.styling_text.color="black"    };    render(){      const styling_text = {color:"red"};        return(<div><h1 style={styling_text} >Change My Colour !! on click</h1><button onClick={this.changeColor}>click me</button></div>        );    }}export default InlineDynamic;

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images