有问题的项目正在使用 React-16.2.0,它能够使用 Fragment 和 Fragment 速记。
https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html
虽然全长语法工作正常......
import React, { Fragment, Component } from 'react';
class TestingFragment extends Component {
render() {
return (
<Fragment>
<span>This is a fragment of text </span>
<div>Another part of the fragment</div>
</Fragment>
)
}
};
export default TestingFragment
速记无法编译,我不知道为什么会这样。例如...
import React, { Component } from 'react';
class TestingFragment extends Component {
render() {
return (
<>
<span>This is a fragment of text </span>
<div>Another part of the fragment</div>
</>
)
}
};
export default TestingFragment
无法编译如下...
Failed to compile
./src/testingFragments.js
Syntax error: Unexpected token (6:4)
4 | render() {
5 | return (
> 6 | <>
| ^
7 | <span>This is a fragment of text </span>
8 | <div>Another part of the fragment</div>
9 | </>
This error occurred during the build time and cannot be dismissed.
这里有什么关于 Fragment 速记语法的遗漏吗?