【发布时间】:2019-10-09 15:55:17
【问题描述】:
我正在尝试在 React 本机项目中实现 styled-jsx。我正在关注本教程:https://github.com/zeit/styled-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>
)
};
}
但我收到以下错误:
============ 更新============
我从 'styled-jsx/style' 中删除了一个导入 _JSXStyle。
styled-jsx/babel:
module.exports = require('./dist/babel'),
{
"plugins": [
["styled-jsx/babel", { "optimizeForSpeed": false }]
]
}
现在我收到此错误:
如果您尝试过,请提供建议。可能是我遗漏了任何文件,请告诉我。
谢谢!
【问题讨论】:
标签: android reactjs react-native styled-components