Reactjs 带有react组件的流错误
我刚刚用react启动了一个新的应用程序,这次我使用的是Flow 我在报告的错误中遇到了一些问题,我认为这些错误不是错误。这是我的班级,有问题:Reactjs 带有react组件的流错误,reactjs,redux,flowtype,Reactjs,Redux,Flowtype,我刚刚用react启动了一个新的应用程序,这次我使用的是Flow 我在报告的错误中遇到了一些问题,我认为这些错误不是错误。这是我的班级,有问题: “严格使用”; //@flow 从“react router dom”导入{HashRouter,Route,Switch}; 从“React”导入React; 从'react redux'导入{connect}; 从“axios”导入axios; 从“./Loader/Loader”导入加载器; 从“./Sidebar/Sidebar”导入侧栏;
“严格使用”;
//@flow
从“react router dom”导入{HashRouter,Route,Switch};
从“React”导入React;
从'react redux'导入{connect};
从“axios”导入axios;
从“./Loader/Loader”导入加载器;
从“./Sidebar/Sidebar”导入侧栏;
从“./Header/Header”导入标题;
将*作为appActions从“../actions/appActions”导入;
类型道具={
调度:功能,
LoadingText:string,
errorTxt:string,
加载:bool,
错误:bool
};
/**
*应用程序组件。
*/
类应用程序扩展了React.Component{
建造师(道具:道具){
超级(道具:道具);
this.data={};
}
componentDidMount(){
get(window.location.protocol+'/'+window.location.host+'/data/app.json')
.然后((响应:object)=>{
this.data=response.data
setTimeout(()=>this.props.dispatch(appActions.apphasload():Function),2000);
}).catch(()=>{
this.props.dispatch(appActions.appHasErrored():函数);
});
}
render():React.Element{
if(this.props.error | | this.props.load){
返回(
{this.props.error?this.props.errorTxt:this.props.loadingText}
)
}否则{
返回(
找不到
)
}
}
};
常量mapStateToProps=(状态:对象)=>{
返回{
加载:state.app.loading,
错误:state.app.error
}
}
导出默认连接(MapStateTops)(应用程序);
以下是错误:
>道具验证中缺少“分派”
src/js/components/App.js:37:37
setTimeout(()=>this.props.dispatch(appActions.apphasload():Function),2000);'道具验证中缺少错误“”
src/js/components/App.js:44:20
if(this.props.error | | this.props.load){
道具验证中缺少“加载”
src/js/components/App.js:44:40
if(this.props.error | | this.props.load){
props验证中缺少“errorTxt”
src/js/components/App.js:48:74
{this.props.error?this.props.errorTxt:this.props.loadingText}
'loadingText'在props验证src/js/components/app.js:48:96中缺失
{this.props.error?this.props.errorTxt:this.props.loadingText}
我不明白的是,为什么它会将它们报告为错误,我已经定义了我的道具。是否支持我每次在渲染方法中使用道具时都使用类型提示?这会使代码变得很难阅读!如果您转到流文档,您可以阅读它 我们在这里将React作为名称空间导入,并将import*作为React from “react”而不是作为默认值从“react”导入react。何时 导入React作为ES模块时,您可以使用任一样式,但 作为名称空间导入使您能够访问React的实用程序类型 这意味着您的泛型解决方案可以工作,如果您将React(如
import*as)作为React from'React'
(而不是import React from'React'
)。
如果希望保留react的当前导入语句,请在类的顶部添加props:props
,并从类声明中删除props
generic,如下所示:
class App extends React.Component {
props: Props
// rest of the code
如果你去看流程文档,你可以阅读它 我们在这里将React作为名称空间导入,并将import*作为React from “react”而不是作为默认值从“react”导入react。何时 导入React作为ES模块时,您可以使用任一样式,但 作为名称空间导入使您能够访问React的实用程序类型 这意味着您的泛型解决方案可以工作,如果您将React(如
import*as)作为React from'React'
(而不是import React from'React'
)。
如果希望保留react的当前导入语句,请在类的顶部添加props:props
,并从类声明中删除props
generic,如下所示:
class App extends React.Component {
props: Props
// rest of the code
谢谢,这就解决了问题!这有文档记录吗?我似乎只找到了使用syntax@riscos3我已经更新了我的答案。如果这回答了您的问题,请将其标记为正确。谢谢:)谢谢,这解决了它!这有文档记录吗?我似乎只找到了使用syntax@riscos3我已经更新了我的答案。如果这回答了你的问题请将其标记为正确。谢谢:)
class App extends React.Component {
props: Props
// rest of the code