Skip to main content

5.03 Setting Styles Dynamically

You can manipulate the style object with any JavaScript code you want and in the end when you then bind it here, it will simply apply this no matter how you edited it.

App.js
    ...
let persons = null;

if (this.state.showPersons) {
persons = (
<div>
{this.state.persons.map((person, index) => {
return (
<Person
click={() => this.deletePersonHandler(index)}
name={person.name}
age={person.age}
key={person.id}
changed={(event) => this.nameChangedHandler(event, person.id)}
/>
);
})}
</div>
);

style.backgroundColor = "red";
}

return (
<div className="App">
...