Mr. J
Mr. J

Reputation: 1839

Cannot change/set Div background-color in React

I am trying to render a with its own background-color. The is rendering, but the background-color is not being changed

import React from 'react'

class Color extends React.Component {

    constructor(props) {
        super(props);    
      }

    mkColor = () => {
        return <div style="background-color: blue;">TEST!!!!</div>       
    }

    render() {
        return this.mkColor()
    }
}

export default Color

How am I screwing this up?

Upvotes: 0

Views: 114

Answers (1)

gdh
gdh

Reputation: 13702

You should use objects for style.

mkColor = () => {
        return <div style={{backgroundColor: 'blue'}}>TEST!!!!</div>       
    }

Upvotes: 2

Related Questions