[英]How to solve this JSX error in react native?
Getting the below error on a new TS file containing JSX for React native:在包含 JSX for React native 的新 TS 文件上出现以下错误:
Unexpected token, expected ","
Below is the code for the component I'm making.下面是我正在制作的组件的代码。 The error appears to
该错误似乎
class TabLabel extends React.PureComponent<IReactionsLabelProps> {
constructor(props: IReactionsLabelProps) {
super(props);
}
render = () => {
const { name, baseUrl, getCustomEmoji, reactions, page, theme } = this.props;
return (
<View style={ sharedStyles.tabView }>
<Emoji
content={name}
standardEmojiStyle={sharedStyles.reactionEmoji}
customEmojiStyle={sharedStyles.reactionCustomEmoji}
baseUrl={baseUrl}
getCustomEmoji={getCustomEmoji}
/>
<Text style={{
...sharedStyles.textBold, color: themes[theme].bodyText
}}>
{ reactions[page]?.usernames?.length }
</Text>
</View>
);
}
}
The linter provides a different error near the "style" prop in the first line of the JSX: Parsing error: '>' expected linter 在 JSX 第一行的 "style" 属性附近提供了一个不同的错误: Parsing error: '>' expected
I am completely stuck and have no idea what's going wrong.我完全被卡住了,不知道出了什么问题。 Full file is available at https://github.com/RocketChat/Rocket.Chat.ReactNative/blob/b1f9916ed8f9a423e356987d934998a139809627/app/views/ReactionsView/index.ts#L45
完整文件位于https://github.com/RocketChat/Rocket.Chat.ReactNative/blob/b1f9916ed8f9a423e356987d934998a139809627/app/views/ReactionsView/index.ts#L45
I'll answer my own question.我会回答我自己的问题。 And I feel exceedingly dumb now, needless to say, having spent literal hours trying to solve this.
而且我现在感觉非常愚蠢,不用说,我花了几个小时试图解决这个问题。
Just had to change the extension of the file from.ts to.tsx, and it worked.只需将文件的扩展名从.ts 更改为.tsx,就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.