wifi: MX-Guest
password: 1-MXGuest2016
Component Types:
Classical Components: lifecycle methods and state
Stateless Functional Components: accept props and return JSX
class DatePicker extends Component {
render(props, state) {
return <a href={props.href}>{ props.label }></a>
}
}//note parentheses instead of braces for automatic return
const Link = ({props}) => (
<a href={props.href}>{props.label}</a>
);Linked State:
Manually Declaring Bound Methods
Linked State Component Class Method: returns a handler function that uses the value of an event to update the named property on state. Less typing & more performant!
class Foo extends Component {
updateText = e => {
this.setState({ text: e.target.value });
};
render({ }, { text }) {
return <input value={text} onInput={this.updateText} />;
}
}class Foo extends Component {
render({ }, { text }) {
return <input value={text} onInput={this.linkState('text')} />;
}
}
Let's look to: Preact-Compat for a use case
Thoughts: Download an example react boilerplate project, convert webpack to preact.
1. See how difficult it is to convert.
2. Compare file sizes.
3. Profile for performance?
(May be too simple to yield good information, but worth a shot)
Install dependencies, build, verify it runs
Install preact, preact-compat.
Update webpack production to alias preact
Install dependencies, build verify it runs, compare file sizes.
Good News First:
1. Converting to preact is very easy in this simple case.
2. Size Results:
react bundle is at 332kb on disk
preact bundle is at 152kb on disk
~54% Code Size Reduction -- not ~95%:
but still:
Pretty, Pretty Good.
Bad News Last
React Performance Tools not available in preact-compat, making profiling rendering performance beyond the scope of this presentation.