简体   繁体   English

如何在 react native 中解决这个 JSX 错误?

[英]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

Complete error below:完整错误如下: 错误代码

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.

相关问题 如何解决 React Native 中的错误“cb 不是函数”? - How to solve an error 'cb is not a function' in React Native? 如何解决本机反应中的 ViewStyle typescript 错误? - How to solve ViewStyle typescript error in react native? 如何在React Native中将字符串转换为jsx - How to convert string to jsx in react native function 作为 JSX - React Native - function as JSX - React Native react-native 如何解决“无法解析模块...”错误? - How to solve "Unable to resolve module..." error with react-native? 如何解决此问题 =&gt; windows 中的 React native 中的端口 8081 已在使用中出现错误 - How to solve this => port 8081 already in use error in React native in windows 我需要如何解决错误 ini 一个信号反应原生 - How I need to solve error ini one signal react native 如何解决 React Native 中的无效钩子调用错误 - How to solve an invalid hook call error in React Native 我如何解决 react native navigation.navigate 错误 - How do I solve react native navigation.navigate error 如何修复错误:相邻的 JSX 元素必须包含在封闭标记中? 在本机反应 - How to fix the error: Adjacent JSX elements must be wrapped in an enclosing tag ? in react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM