Comments (4)
This was one of the apps I wrote to learn React, so there are lots of things which need to be addressed (getting rid of mixins, replacing state management with something which better enables rendering to be optimised, etc.).
It already uses a bunch of ES6 syntax and a re-do would use more of it - ES6 import
syntax etc. - but I'm not a fan of extends Component
because you lose autobinding and have to enable experimental features in Babel to make it as palatable as createClass
, since ES6 classes are unfortunately just weak sugar.
from react-hn.
I see, thanks!
from react-hn.
Regarding extends Component, tbh, even though you may wind up using experimental decorators for class syntax, it isn't bad... one benefit, is you can still use straight function syntax for example with redux, to export a default as a wrapped version, as well as a raw version for testing against...
import { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { bind, ... } from 'core-decorators';
...
export FooComponent extends Component {
// declare mapping with the component as static members
static mapProps = (state) => ...
static mapActions = (dispatch) => ...
@bind
onClick() {
this.actions.onClick(...);
}
render() {
// note: bound properties won't trigger a mismatch/rerender.
return <button onClick={this.onClick}>ClickMe</button>;
}
}
export default connect(FooComponent.bindProps, FooComponent.mapActions)(FooComponent);
Though, I find that for the most part, In practice, I'll do the state/action mapping a little higher, and pass actions/properties into pure-render functions. I really don't like the createClass
syntax at all.
from react-hn.
I'll probably come round to it once I've given the sugar its 5 minutes. I have to write some of the documentation for the upcoming version of nwb using extends Component
as some of the transforms nwb enables by default don't support createClass
and don't seem to have plans to.
Class properties (and decorators) are now stage 2, so will work out of the box with zero configuration in the upcoming version of nwb, which is the kind of sweet spot Babel 5 had reached with object rest/spread syntax when I bought into that.
from react-hn.
Related Issues (20)
- LINK SEEMS DOWN HOT 2
- Add a section for stories you've looked at HOT 1
- Investigate using Lighthouse HOT 1
- Offline mode is broken HOT 5
- fresh repo clone fails during postinstall HOT 4
- Error - Not able to do 'npm run build' HOT 4
- manifest.d41d8cd9.js:1 Uncaught SyntaxError: Unexpected token <
- lighthouse: 'URL responds with a 200 when offline' doesn't pass HOT 2
- Points is not consistent
- Top stories HOT 1
- npm install fails HOT 2
- Sourcemap seems to be HTML
- Experiment: port over to using sw-helpers
- Question: react-router HOT 2
- Reloading development server HOT 1
- [email protected]: Failed to load resource: net::ERR_UNSAFE_REDIRECT
- Module not found: Error: Cannot resolve module 'history/lib/createHashHistory' HOT 1
- Why does show the first page items, then show blinking dots, then show the items again?
- WC HOT 2
- Live link down HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-hn.