Mateusz Pokora
Binar::Apps
Small reusable components
<div class='app' style="background-color: #faf;">
<button class='change-color-button'>
Change component background
</button>
</div>
<script>
$(document).ready(function() {
$('.change-color-button').click(function() {
$('.app').css('background-color', '#afa');
});
});
</script>
// App.js
import React, { Component } from 'react';
class App extends Component {
changeColor() {
this.setState({
backgroundColor: '#afa'
});
}
render() {
return (
<div className="App" style={{ backgroundColor: this.state.backgroundColor }}>
<button onClick={this.changeColor}>Change component background</button>
</div>
);
}
}
export default App;
// index.js
...
ReactDOM.render(
<App />,
document.getElementById('root')
);
...
<body>
<div id="root"></div>
</body>
...
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.
npm is the package manager for JavaScript.