Giter Club home page Giter Club logo

Comments (5)

brigand avatar brigand commented on September 22, 2024

You have to write it like this:

class MyComponent extends React.Component {
  props: Props;
}
export default connect()(MyComponent);

I'd accept a PR adding decorator support. I might implement it eventually but it's not a priority, especially considering it's disabled in babel pending spec changes.

from babel-plugin-flow-react-proptypes.

ismay avatar ismay commented on September 22, 2024

I did try it without the decorator support, but I'll double check and see if I can get it to work in the way that you describe. Will let you know if I encounter anything.

from babel-plugin-flow-react-proptypes.

ismay avatar ismay commented on September 22, 2024

Ok, I tried it again for a container component and for a regular es6 class component. In both cases babel-plugin-flow-react-proptypes does not set the proptypes for me. In my other use cases it does work correctly. The container component for which it doesn't work:

/* @flow */

import { connect } from 'react-redux';
import React, { Component } from 'react';
import GapAnalysis from '../pages/GapAnalysis';
import { requestFacts, requestIndicators, requestVersions } from '../actions';

type Props = {
  facts: Object[],
  indicators: Object[],
  versions: Object[],
  requestFacts: Function,
  requestIndicators: Function,
  requestVersions: Function,
};

export class Unconnected extends Component {
  componentWillMount() {
    this.props.requestIndicators();
    this.props.requestVersions();
  }

  props: Props;

  render() {
    return <GapAnalysis {...this.props} />;
  }
}

const mapStateToProps = (state) => ({
  facts: state.facts.items,
  indicators: state.indicators.items,
  versions: state.versions.items,
});

const actions = { requestFacts, requestIndicators, requestVersions };

export default connect(mapStateToProps, actions)(Unconnected);

But maybe I'm doing something wrong here.

from babel-plugin-flow-react-proptypes.

brigand avatar brigand commented on September 22, 2024

That exact code works for me.

$ babel --presets es2015,react --plugins flow-react-proptypes a.js
// ...
Unconnected.propTypes = {
  facts: require('react').PropTypes.arrayOf(require('react').PropTypes.object).isRequired,
  indicators: require('react').PropTypes.arrayOf(require('react').PropTypes.object).isRequired,
  versions: require('react').PropTypes.arrayOf(require('react').PropTypes.object).isRequired,
  requestFacts: require('react').PropTypes.func.isRequired,
  requestIndicators: require('react').PropTypes.func.isRequired,
  requestVersions: require('react').PropTypes.func.isRequired
};
// ...

from babel-plugin-flow-react-proptypes.

ismay avatar ismay commented on September 22, 2024

Hmm strange, I must be doing something wrong then. I think this issue can be closed then, and should I find anything I'll let you know. Thanks for the feedback!

from babel-plugin-flow-react-proptypes.

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.