[英]How to use the npm package “react-classy” in react?
I'm going to use the "npm" package "react-classy" in my react project. 我将在我的react项目中使用“ npm”包“ react-classy”。 But I came across the syntax issue in my code.
但是我在代码中遇到了语法问题。 I created the react classy project by using "npx create-react-app classy".
我使用“ npx create-react-app classy”创建了react classy项目。 And then I installed the react-classy package in classy project.
然后我在经典项目中安装了react-classy软件包。 And I created the button.js for using the react-classy package.
我创建了button.js以使用react-classy包。 I imported the button.js in app.js.
我将button.js导入了app.js。 And then I came across the syntax issue in the button.js.
然后我在button.js中遇到了语法问题。 Here is the following file:
这是以下文件:
import React, { Component } from 'react';
import Classy from 'react-classy';
@Classy
export default class Button extends Component {
static style = `
.button {
background: blue;
}
`
render() {
return (
<button className="button">
{this.props.children}
</button>
);
}
}
In this file, @ is the issue. 在此文件中,@是问题。 Please let me know what is the reason.
请让我知道原因。 Thanks.
谢谢。
To use decorators in your create-react-app project you'll have to eject 要在您的create-react-app项目中使用装饰器,您必须退出
npm eject
then 然后
npm install --save-dev babel-plugin-transform-decorators-legacy
then in your package.json add this 然后在你的package.json中添加这个
"babel": {
"plugins": ["babel-plugin-transform-decorators-legacy"],
"presets": ["react-app"]
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.