【发布时间】:2018-10-20 01:25:00
【问题描述】:
我已经使用styled-jsx@2.2.6 安装了 styled-jsx,并且正在做类似的事情:
import React, { Component } from 'react'
export default Index class extends Component {
constructor(props){
super(props)
this.state = { clicked: false}
}
render(){
return(){
<div>
<button onClick={() => this.setState({clicked: !this.state.clicked}}}>Hello</button>
<style jsx>{`
button {
background-color: ${this.state.clicked ? 'red' : 'blue'}
}
`}<style>
}
}
}
没有任何样式被应用,我在控制台中注销了单击状态并且它正在被更改。
【问题讨论】:
-
您是否将 styled-jsx 添加到您的 babel 插件中?
-
我正在使用 gatsby。它有一个
gatsby-plugin-styled-jsx,位于gatsby-config中。我还没有在 .babelrc 中这样做,我该怎么做呢? -
{ "插件": [ "styled-jsx/babel" ] }
-
现在我收到
Uncaught SyntaxError: Unexpected identifier的错误 -
这个错误是在哪个过程中出现的,你能发布整个输出吗?
标签: reactjs styles jsx styled-components