5

I am trying to add inline style to the element using reactjs. I found

var divStyle = {
  color: 'white',
  backgroundImage: 'url(' + imgUrl + ')'
};

ReactDOM.render(<div style={divStyle}>Hello World!</div>, mountNode);

in reactjs docs. Thing is, it is not working without JSX.

I tried doing this.

return (
        React.DOM.div({ className: 'eventsOuter'},
              {style:'divStyle'}
        )

But the style part is not working.

Is there any way to fix this?

1
  • Maybe {style: divStyle} ? Commented Jan 11, 2016 at 11:46

1 Answer 1

3

You need to pass variable instead of variable name:

React.DOM.div({
    className: 'eventsOuter',
    style: divStyle
}, 'Hello World!')

Also you can compile online: on the babel website

Sign up to request clarification or add additional context in comments.

1 Comment

"You need to pass variable instead of variable name" is quite confusing. I think you mean - You need to pass a variable instead of the string of a variable name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.