Giter VIP home page Giter VIP logo

Comments (4)

insin avatar insin commented on September 15, 2024 2

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.

LeoAJ avatar LeoAJ commented on September 15, 2024

I see, thanks!

from react-hn.

tracker1 avatar tracker1 commented on September 15, 2024

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.

insin avatar insin commented on September 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.