Created
May 21, 2016 09:24
-
-
Save adamniedzielski/9f96d418c34175543fea6a53546f14cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// React.js - wprowadzenie | |
// Czym jest i gdzie jest jego miejsce? | |
// Jak uczyć się Reacta? | |
// JSX | |
<h1> | |
{document.title} | |
</h1> | |
<input type="text" value={someVariable} /> | |
<input type="text" value={orFunctionCall()} /> | |
<MyCustomComponent someKey={someVariable} /> | |
// Pierwszy komponent | |
var HelloWorld = React.createClass({ | |
render: function() { | |
return ( | |
<h1> | |
Hello World! | |
</h1> | |
); | |
} | |
}); | |
// props | |
<HelloWorld name={name} /> | |
var HelloWorld = React.createClass({ | |
render: function() { | |
return ( | |
<h1> | |
Hello {this.props.name}! | |
</h1> | |
); | |
} | |
}); | |
// state cz. 1 | |
var HelloWorld = React.createClass({ | |
getInitialState: function() { | |
return { | |
name: "Adam" | |
}; | |
}, | |
render: function() { | |
return ( | |
<h1> | |
Hello {this.state.name}! | |
</h1> | |
); | |
} | |
}); | |
// state cz. 2 | |
var HelloWorld = React.createClass({ | |
getInitialState: function() { | |
return { | |
name: "Adam" | |
}; | |
}, | |
render: function() { | |
return ( | |
<div> | |
<h1> | |
Hello {this.state.name}! | |
</h1> | |
<input type="text" | |
value={this.state.name} | |
onChange={this.handleNameChange} /> | |
</div> | |
); | |
}, | |
handleNameChange: function(event) { | |
this.setState({ | |
name: event.target.value | |
}); | |
} | |
}); | |
// JSX raz jeszcze | |
var HelloWorld = React.createClass({ | |
render: function() { | |
var items = [1, 2, 3, 4].map(function (number) { | |
return ( | |
<li> | |
{number} | |
</li> | |
); | |
}); | |
return ( | |
<ul> | |
{items} | |
</ul> | |
); | |
} | |
}); | |
// cykl życia komponentu | |
var HelloWorld = React.createClass({ | |
componentDidMount: function() { | |
this.interval = setInterval( | |
this.refresh, | |
this.props.refreshTime | |
); | |
}, | |
componentWillUnmount: function() { | |
clearInterval(this.interval); | |
}, | |
refresh: function() { | |
// [...] | |
}, | |
render: function() { | |
// [...] | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment