问题描述
我看到以下情况很好:
const Tab = connect( mapState, mapDispatch )( Tabs );
export default Tab;
然而,这是不正确的:
export default const Tab = connect( mapState, mapDispatch )( Tabs );
但这很好:
export default Tab = connect( mapState, mapDispatch )( Tabs );
可以解释为什么 const
是导出默认
无效?这是不必要的补充吗?声明为导出默认值
的任何内容都假定为 const
或类似的?
Can this be explained please why const
is invalid with export default
? Is it an unnecessary addition & anything declared as export default
is presumed a const
or such?
推荐答案
const
就像让
,( VariableStatement,声明),用于在块中定义标识符。
const
is like let
, it is a LexicalDeclaration (VariableStatement, Declaration) used to define an identifier in your block.
您正在尝试将其与默认
关键字混合, 需要 HoistableDeclaration,ClassDeclaration 或 AssignmentExpression 跟随它。
You are trying to mix this with the default
keyword, which expects a HoistableDeclaration, ClassDeclaration or AssignmentExpression to follow it.
因此它是 SyntaxError 。
如果你想要 const
你需要提供标识符,而不是使用 default
。
If you want to const
something you need to provide the identifier and not use default
.
export
本身接受 VariableStatement 或声明 to it'是的。
export
by itself accepts a VariableStatement or Declaration to it's right.
AFAIK导出本身不应该在当前范围内添加任何东西。
AFAIK the export in itself should not add anything to your current scope.
Tab
成为 AssignmentExpression ,因为它的名称为 default
Tab
becomes an AssignmentExpression as it's given the name default
这里 Tab = connect( mapState,mapDispatch)(Tabs);
是 AssignmentExpression 。
这篇关于为什么`Export Default Const`无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!