Answer the question
In order to leave comments, you need to log in
How to properly use React and Flow with ES6 syntax?
Trying to use React and Flow with ES6 syntax and getting error: line 9 col 3 React element: Hello - Error:
in app.jsx file:
/* @flow */
var React = require('react');
var Hello = require('../src/components_flow/hello/hello');
//var Input = require('../src/components_flow/input/input');
//React.renderComponent(<Hello name="World" />, document.getElementById('react-container'));
React.render(
<Hello name="World"/>,
document.getElementById('react-container'));
/* @flow */
var React = require('react');
class Hello extends React.Component {
render(): any {
return <div>Hello {this.props.name}</div>;
}
}
module.exports = Hello;
gulp.task('react', function () {
return gulp.src([
'./src/components_flow/hello/hello.jsx',
'./src/components_flow/input/input.jsx',
'./src/app.jsx'],
function (er, files) {
// files is an array of filenames.
// If the `nonull` option is set, and nothing
// was found, then files is ["**/*.js"]
// er is an error object or null.
//console.log(files);
})
.pipe(flow({
all: false,
weak: false,
killFlow: false,
beep: false,
abort: false //abort the gulp task after the first Typecheck error
}))
.pipe(react({stripTypes: true, harmony: true}))
.pipe(gulp.dest(function(file) {
return file.base;
}));
});
gulp react
/* @flow */
var React = require('react');
type HelloProps = {
name: string
};
class Hello extends React.Component {
static propTypes: { name: string };
static defaultProps: { name: string };
constructor(props: HelloProps) {
super(props);
}
render(): any {
return <div>Hello {this.props.name}</div>;
}
}
module.exports = Hello;
Answer the question
In order to leave comments, you need to log in
Read what flowtype.org is for (A STATIC TYPE CHECKER FOR JAVASCRIPT)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question