Styled-JSX 变量不起作用

Styled-JSX variables not working

我已经使用 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>
  }
 }
}

没有应用任何样式,我在控制台注销了单击状态并且正在更改它。

这是工作示例。你那里有很多错别字。我假设您没有使用通常指出所有这些问题的适当 IDE。

这是工作代码:https://stackblitz.com/edit/react-3ttfch

这是您的固定无打字代码:

class Index 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>
      </div>
    );
  }
}