Render Style in HTML Element in React


Wie kann man ein Style Element in React in den Render() Pfad einbringen?



render() {

return (


<p style="background:red">HTML Content</p>





<p style={{ background: 'red' }}>HTML Content</p>





Fehlermeldung in React bei <p Style="background:red" >




Unhandled Rejection (Error): The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX. in p (at Article.js:97) in div (at Article.js:89) in div (at Article.js:78)

in Article (created by Context.Consumer)

in Route (at App.js:22) i

n div (created by Container)

in Container (at Layout.js:12)

in div (at Layout.js:10)

in Layout (at App.js:20)

in App (at src/index.js:13)

in Router (created by BrowserRouter)

in BrowserRouter (at src/index.js:12)


25 stack frames were collapsed.



  50 |        //console.log("this.state=" + this.state);
 51 |        //console.log(this.state);
 52 |
> 53 |        this.setState(state => ({
    | ^  54 |            idarticle   :data.idArticle,
 55 |            iduser      :data.idUser,
 56 |            title       :data.title,

View compiled