Android 样式化jsx反应本机
我试图在React原生项目中实现Android 样式化jsx反应本机,android,reactjs,react-native,styled-components,Android,Reactjs,React Native,Styled Components,我试图在React原生项目中实现样式化的jsx。我将学习本教程: 我添加了以下代码: .babelrc: { "presets": [ "@babel/preset-env" ], "plugins": [ "@babel/plugin-proposal-object-rest-spread" ] } import React, { Component } from 'react'; import { View } from 'r
样式化的jsx
。我将学习本教程:
我添加了以下代码:
.babelrc:
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-object-rest-spread"
]
}
import React, { Component } from 'react';
import { View } from 'react-native';
import _JSXStyle from 'styled-jsx/style'
export default class HomeScreen extends React.Component {
render() {
return (
<div className="jsx-123">
<p className="jsx-123">only this paragraph will get the style :)</p>
<_JSXStyle id="123">{`p.jsx-123 {color: red;}`}</_JSXStyle>
</div>
)
};
}
module.exports = require('./dist/babel'),
{
"plugins": [
["styled-jsx/babel", { "optimizeForSpeed": false }]
]
}
屏幕:
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-object-rest-spread"
]
}
import React, { Component } from 'react';
import { View } from 'react-native';
import _JSXStyle from 'styled-jsx/style'
export default class HomeScreen extends React.Component {
render() {
return (
<div className="jsx-123">
<p className="jsx-123">only this paragraph will get the style :)</p>
<_JSXStyle id="123">{`p.jsx-123 {color: red;}`}</_JSXStyle>
</div>
)
};
}
module.exports = require('./dist/babel'),
{
"plugins": [
["styled-jsx/babel", { "optimizeForSpeed": false }]
]
}
现在我遇到了这个错误:
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-object-rest-spread"
]
}
import React, { Component } from 'react';
import { View } from 'react-native';
import _JSXStyle from 'styled-jsx/style'
export default class HomeScreen extends React.Component {
render() {
return (
<div className="jsx-123">
<p className="jsx-123">only this paragraph will get the style :)</p>
<_JSXStyle id="123">{`p.jsx-123 {color: red;}`}</_JSXStyle>
</div>
)
};
}
module.exports = require('./dist/babel'),
{
"plugins": [
["styled-jsx/babel", { "optimizeForSpeed": false }]
]
}
如果你尝试过这个,请给出建议。可能是我丢失了任何文件,请告诉我
谢谢大家! 你的错误
您尝试了如何工作的示例。如果库开发人员指出编译后的外观,那么请按照文档进行操作。为了让你更好地理解,我在这里讲 首先,安装软件包:
npm安装--保存样式化的jsx
接下来,将样式化的jsx/babel
添加到babel配置中的插件中:
{
"plugins": [
"styled-jsx/babel"
]
}
现在将
添加到您的代码中,并用CSS填充:
export default () => (
<div>
<p>only this paragraph will get the style :)</p>
{ /* you can include <Component />s here that include
other <p>s that don't get unexpected styles! */ }
<style jsx>{`
p {
color: red;
}
`}</style>
</div>
)
导出默认值()=>(
只有此段落将获得样式:)
{/*您可以在此处包括
其他未获得意外样式的s!*/}
{`
p{
颜色:红色;
}
`}
)
注意:根据文档,它应该有效 你的错误
您尝试了如何工作的示例。如果库开发人员指出编译后的外观,那么请按照文档进行操作。为了让你更好地理解,我在这里讲
首先,安装软件包:
npm安装--保存样式化的jsx
接下来,将样式化的jsx/babel
添加到babel配置中的插件中:
{
"plugins": [
"styled-jsx/babel"
]
}
现在将
添加到您的代码中,并用CSS填充:
export default () => (
<div>
<p>only this paragraph will get the style :)</p>
{ /* you can include <Component />s here that include
other <p>s that don't get unexpected styles! */ }
<style jsx>{`
p {
color: red;
}
`}</style>
</div>
)
导出默认值()=>(
只有此段落将获得样式:)
{/*您可以在此处包括
其他未获得意外样式的s!*/}
{`
p{
颜色:红色;
}
`}
)
注意:根据文档,它应该有效 您能告诉我在哪里可以找到这个样式化的jsx/babel吗?目前我已经在.babelrcstill中添加了此代码。我将收到该文档错误:(.你能解释一下文件和代码的位置吗?因为我第一次尝试npm安装--save styled jsx
安装后,你会在node_modules上得到它,因为我有这个代码:module.exports=require('./dist/babel'))我是否应该在此之后或在任何arrayNo中添加此代码。应该可以。如果不能,请重新运行您的项目。您能告诉我在哪里可以找到此样式的jsx/babel吗?目前我已在中添加此代码。babelrcstill我收到该文档错误:(.你能解释一下文件和代码的位置吗?因为我第一次尝试npm安装--save styled jsx
安装后,你会在node_modules上得到它,因为我有这个代码:module.exports=require('./dist/babel'))我是否应该在此之后或在任何arrayNo中添加此代码。它应该可以工作。如果不可以,请重新运行您的项目。