wprowadzenie
Czym jest React?
const PageHeader = () => (
<header>
<h1>My awesome page</h1>
</header>
)
const PageHeader = () => (
React.createElement(
'header',
null,
React.createElement(
'h1',
null,
'My awesome page'
)
)
)
class PageHeader extends React.Component {
render() {
return (
<header>
<h1>My awesome page</h1>
</header>
)
}
}
class Counter extends React.Component {
state = {
current: 0
}
increment = this.setState(curr => ({ current: curr + 1}))
render() {
return (
<button onClick={this.increment}>
{this.state.current}
</button>
)
}
}
const Article = props => (
<article>
<h2>{props.title}</h2>
<p>{props.content}</p>
</article>
)
<Article title={'Breaking news!'} content={'lorem ipsum'} />
autor: Dan Abramov
const HOC = Component => {
return class extends React.Component {
render() {
return <Component {...this.props} authenticated/>
}
}
}
const Wrapped = HOC(SomeComponent)
...
<Wrapped />
const WorldProvider = ({ render }) => (
<header>
{render('World')}
</header>
)
...
<WorldProvider render={data => (
<h1>Hello {data.target}</h1>
)}/>