Javascript 流量don';我不懂道具
看看这门课:Javascript 流量don';我不懂道具,javascript,reactjs,properties,ecmascript-6,flowtype,Javascript,Reactjs,Properties,Ecmascript 6,Flowtype,看看这门课: /* @flow */ import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; const mapStateToProps = (state) => ({ email: ... }); @connect(mapStateToProps) class UserControlPanel
/* @flow */
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
const mapStateToProps = (state) => ({
email: ...
});
@connect(mapStateToProps)
class UserControlPanel extends PureComponent {
static propTypes = {
email: PropTypes.string
}
logout = (ev:any) => {
ev.preventDefault();
...
}
render() {
const { email } = this.props;
return (
<div className="ucp">
...
</div>
);
}
}
export default UserControlPanel;
或者这个:
type Props = {
email: string;
};
@connect(mapStateToProps)
class UserControlPanel extends PureComponent<Props> {
static propTypes = {
email: PropTypes.string
}
类型道具={
电子邮件:字符串;
};
@连接(MapStateTops)
类UserControlPanel扩展了PureComponent{
静态类型={
电子邮件:PropTypes.string
}
两者都不起作用。只使用组件而不是PureComponent也不起作用
如何使flow了解我的道具类型,并且不再显示错误消息?如果您已经在使用flow Type验证您的类型,则不应使用道具类型 相反,请尝试以下操作:
/* @flow */
import * as React from 'react';
import { connect } from 'react-redux';
const mapStateToProps = state => ({
email: ...
});
type Props = {
email: string,
};
@connect(mapStateToProps)
export default class UserControlPanel extends React.PureComponent<Props> {
render() {
const { email } = this.props;
return (
<div className="ucp">
...
</div>
);
}
}
/*@flow*/
从“React”导入*作为React;
从'react redux'导入{connect};
常量mapStateToProps=状态=>({
电子邮件:。。。
});
类型道具={
电子邮件:string,
};
@连接(MapStateTops)
导出默认类UserControlPanel扩展React.PureComponent{
render(){
const{email}=this.props;
返回(
...
);
}
}
这不是重点,但我刚刚更新了我的流量箱,现在可以使用了。谢谢。
/* @flow */
import * as React from 'react';
import { connect } from 'react-redux';
const mapStateToProps = state => ({
email: ...
});
type Props = {
email: string,
};
@connect(mapStateToProps)
export default class UserControlPanel extends React.PureComponent<Props> {
render() {
const { email } = this.props;
return (
<div className="ucp">
...
</div>
);
}
}